//
//  TSCVCTest.m
//  Tsc_IOS
//
//  Created by Rio on 15-6-5.
//  Copyright (c) 2015年 idream. All rights reserved.
//

#import "TSCVCTest.h"
#import "TSCSDK.h"
#import <MobileCoreServices/MobileCoreServices.h>
#import <AssetsLibrary/AssetsLibrary.h>





@interface TSCVCTest ()

@end

@implementation TSCVCTest

+ (id) vcTestWithStoryBoard {
    UIStoryboard * sb = [UIStoryboard storyboardWithName:UI_STORYBOARD_NAME_MAIN bundle:[NSBundle mainBundle]];
    return [sb instantiateViewControllerWithIdentifier:@"test"];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

//    [self testCheckUtil];
    
//    [self testToast];
//    [self testSpinner];
//    [self testLinerLayout];
//    [self testLinearLayout2_2];
//    [self testMyGCSelector];
//    [self testMyGCSelector2];
//    [self testMyGCSelector3];
//    [self testGCSelectorDialog];
//    [self testSubviewDeterminSuperview];
//    [self testNSLayoutConstraint];
//    [self testSubviewOrder];
//    [self testLinearLayout2_3];
    
//        [self testDialogConstraintsForWidthAndHeight];
//    [self testSubviewExtendsLinearLayoutSuperview];
//        [self testAddSubviewToLinearLayout];
//    [self testAddSubviewToSuperviewSeperate];
//    [self testMyDialog0];
//    [self testDialogReplaceContent];
//    [self testMyDialog];
//    [self testConstraint];
    
//    [self testUploadPicDialog];
//    [self testFile];
//    [self testPhotoEditor];
    
//    [self testMyClickBtn];
    
//    [self testHTTPGet];
    
//    [self testPopMenu];
//    [self testTimestamp];
//    [self testDBUtilMsg];
//    [self testSidebar];
//    [self testLoadXibFullScreen];
//    [self testAddConstraintUpdateFrame];
    
//    [self testDatepicker];
//    [self testAddConstraintUpdateFrame2];
    
//    [self testInsetAppDB];
    
//    [self testTextView];
    
    [self testRadioButton];
    
    return;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

// ====================================================================================================


- (void) testStatusBarNaviBarFrame {
    // 将以下代码放在一个具有statusBar、naviBar的VC中，横屏、竖屏都测试一下
    // 横屏：
    // 1024
    // 768
    // 1024
    // 20
    // 1024
    // 44
    // 竖屏：
    // 768
    // 1024
    // 768
    // 20
    // 768
    // 44
    NSLog(@"winW:%f", UI_SCREEN_WIDTH);
    NSLog(@"winH:%f", UI_SCREEN_HEIGHT);
    NSLog(@"statusBarW:%f", [TSCMyUIUtil getStatusBarFrame].size.width);
    NSLog(@"statusBarW:%f", [TSCMyUIUtil getStatusBarFrame].size.height);
    NSLog(@"naviBarW:%f", [TSCMyUIUtil getNavigationBarFrame:self].size.width);
    NSLog(@"naviBarH:%f", [TSCMyUIUtil getNavigationBarFrame:self].size.height);
}

- (void) testCheckUtil {
    NSLog(@"%i", [TSCMyCheckUtil checkWithString:@"" regexType:RegexTypeGoodsClassIds]); // 0
    NSLog(@"%i", [TSCMyCheckUtil checkWithString:@"1" regexType:RegexTypeGoodsClassIds]); // 1
    NSLog(@"%i", [TSCMyCheckUtil checkWithString:@"1," regexType:RegexTypeGoodsClassIds]); // 0
    NSLog(@"%i", [TSCMyCheckUtil checkWithString:@"1,2" regexType:RegexTypeGoodsClassIds]); // 1
    NSLog(@"%i", [TSCMyCheckUtil checkWithString:@"1,2,3" regexType:RegexTypeGoodsClassIds]); // 1
    NSLog(@"%i", [TSCMyCheckUtil checkWithString:@"10" regexType:RegexTypeGoodsClassIds]); // 1
    NSLog(@"%i", [TSCMyCheckUtil checkWithString:@"10,20" regexType:RegexTypeGoodsClassIds]); // 1
    NSLog(@"%i", [TSCMyCheckUtil checkWithString:@"1,2,30" regexType:RegexTypeGoodsClassIds]); // 1
}

- (void) testAddNilToArrOrDic {
    NSMutableArray *arr = [NSMutableArray array];
//    [arr addObject:nil]; // 运行时错误，不允许！
    [arr addObject:[NSNull null]];
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
//    [dic setObject:nil forKey:@"name"]; // 运行时错误，不允许！
    [dic setObject:[NSNull null] forKey:@"name"];
    
    NSLog(@"arr: %@", arr);
    NSLog(@"dic: %@", dic);
    
    
}

- (void) testAccessArr {
    NSInteger arr [3];
    arr[0] = 1;
    
    NSLog(@"%li", arr[0]);
        NSLog(@"%li", arr[1]);
        NSLog(@"%li", arr[2]);
//    NSLog(@"%i", arr[3]);
}

- (void) testAddToArray {
    NSMutableArray * arr = [NSMutableArray array];
    [arr addObject:@"1"];
    [arr addObject:@"2"];
    [arr addObject:@"3"];
    [arr addObject:nil];

    NSLog(@"%@", arr);
//    NSLog(@"%@", [arr objectAtIndex:0]);
//        NSLog(@"%@", [arr objectAtIndex:1]);
//        NSLog(@"%@", [arr objectAtIndex:2]);
}

- (void) testToast {
    [TSCMyToast makeTextWithString:@"试试吧，这是一段很长的话，看看这么长的一段话到底能不能达到屏幕末尾？换行吗？还没换行啊，这说明你的设备屏幕分辨率很高啊！不错！可以试着把屏幕进行旋转，这样可能就可以换行了！快试试吧！" ti:200];
//    [TSCMyToast makeTextWithString:@"试试吧，这是一段不长的话！" ti:200];
}

- (void) testSpinnerSetSelectedItem  {
    TSCMySpinner * sp = [[TSCMySpinner alloc]init];
    sp.frame = CGRectMake(50, 50, 200, 30);
    [self.view addSubview:sp];
    
    [sp prepareData_P1:^{
        NSArray * dataArray = [NSArray arrayWithObjects:@"选项一",@"选项二", @"选项三", @"选项四", @"选项五", @"选项六", @"选项七", nil];
        
        [sp.dataArray addObjectsFromArray:dataArray];
    } completionHandler:^{
        [sp applyData];
        
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            [NSThread sleepForTimeInterval:2];
            
            dispatch_async(dispatch_get_main_queue(), ^{
                [sp setSelectedItem:2];
            });
        });
    }];
}

- (void) testMacroFunc {
    NSInteger arr1 [3] = {1,2,3};
    NSInteger arr2 [5] = {11,12,13,14,15};
    
    NSLog(@"arr1 len:%li",arr_count(arr1));
    NSLog(@"arr2 len:%li",arr_count(arr2));
}

- (void) testModifyArr:(NSInteger [2])arr {
    arr[0] = 11;
    arr[1] = 12;
    
    // 在main方法中：
//    NSInteger arr [2] = {1,2};
//    NSLog(@"arr原来:%i, %i", arr[0], arr[1]);
//    [self testModifyArr:arr];
//    NSLog(@"arr改后:%i, %i", arr[0], arr[1]);
}

- (void) testSQLSelectNullColumn {
    NSArray * arr = [TSCMyDBHelper selectWithSql:[NSString stringWithFormat:
                                                  @"SELECT C1.id, C1.name AS name1, C2.name AS name2 FROM %@ AS C1 LEFT JOIN %@ AS C2 ON (C2.id = 1212) WHERE C1.id = 1;",
                                                  DB_TABLE_NAME_CITY,
                                                  DB_TABLE_NAME_CITY
                                                  ]];
    NSLog(@"arr: %@", arr);
    NSDictionary * dic = [arr objectAtIndex:0];
    if ([dic objectForKey:@"name2"] == [NSNull null]) {
        NSLog(@"null!");
    }
}

- (void) testSQLSelectSameColumn {
//    NSArray * arr = [TSCMyDBHelper selectWithSql:@"SELECT id, name, name, name FROM tsc_city WHERE id = 12;"];
    //    NSArray * arr = [TSCMyDBHelper selectWithSql:@"SELECT id, name AS n1, name AS n2, name FROM tsc_city WHERE id = 12;"];
    NSArray * arr = [TSCMyDBHelper selectWithSql:@"SELECT id, name AS n1, name AS n2, name AS n3 FROM tsc_city WHERE id = 12;"];
     NSLog(@"arr: %@", arr);
}

- (void) testSQLSelectNoThing {
    NSArray * arr = [TSCMyDBHelper selectWithSql:@"SELECT id, name FROM tsc_city WHERE id = 1212;"];
//    NSArray * arr = [TSCMyDBHelper selectWithSql:@"SELECT id, name FROM tsc_city WHERE id = 12;"];
    
    NSLog(@"arr: %@", arr);
    
//    NSDictionary * dic = [NSDictionary dictionary];
//    NSLog(@"dic element: %@", [dic objectForKey:@"keyNotExist"]);
    
}

- (void) testMyGCSelector {
//    TSCMyGCSelector * gcSelector = [[TSCMyGCSelector alloc]init];
//    gcSelector.layoutWidth = LayoutWHTypeNone;
//    gcSelector.layoutHeight = LayoutWHTypeWrapContent;
////    gcSelector.frame = CGRectMake(10, 50, 260, 0);
////    gcSelector.frame = CGRectMake(10, 50, 150, 0);
//    gcSelector.bounds = CGRectMake(0, 0, 280, 0);
//    gcSelector.center = CGPointMake(UI_SCREEN_WIDTH / 2, 50);
//    gcSelector.maxRows = 3;
////    gcSelector.
//    
////    gcSelector.center = CGPointMake(UI_SCREEN_WIDTH / 2, UI_SCREEN_HEIGHT / 2);
////    gcSelector.backgroundColor = COLOR_MT_DIALOG_MODAL;
////    gcSelector.ma
//    [self.view addSubview:gcSelector];
//    
//    [gcSelector setupViewData_1];
//    
//    
////    gcSelector.frame = CGRectMake(10, 50, 150, 0);
//    
////    gcSelector.frame = CGRectMake(10, 50, 300, 0);
}

- (void) testMyGCSelector2 {
    TSCMyGCSelector * gcSelector = [[TSCMyGCSelector alloc]init];
//    gcSelector = CGRectMake(50, 50, 400, 400);
    gcSelector.backgroundColor = [UIColor lightGrayColor];
    gcSelector.uiElementHeight = 30.0f;
    gcSelector.uiFontSize = [TSCMyUIUtil getSystemDefaultFont].pointSize; // 13.0f
//    gcSelector.uiPadding = 10.0f;
    [self.view addSubview:gcSelector];
    
//    // 添加约束（一）
//    gcSelector.translatesAutoresizingMaskIntoConstraints = NO;
//    [NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-50-[gcSelector(600)]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(gcSelector)]];
//    [NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-50-[gcSelector]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(gcSelector)]]; // 注：不指定高度，因为高度会“动态变化”
    
    // 添加约束（二）
    gcSelector.translatesAutoresizingMaskIntoConstraints = NO;
    [NSLayoutConstraint constraintWithItem:gcSelector attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1.0f constant:0.0f].active = YES;
    [NSLayoutConstraint constraintWithItem:gcSelector attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeRight multiplier:1.0f constant:0.0f].active = YES;
    
    
    // 绘制界面，并填充数据
    [gcSelector drawUI];
    [gcSelector setupViewData_1];
    
    // 测试公共方法
    //
    TSCMyClickBtn * btn1 = [TSCMyClickBtn buttonWithType:UIButtonTypeSystem];
    [btn1 setTitle:@"-getSelectedGCIdsStr" forState:UIControlStateNormal];
    btn1.btnClickedListener = ^(TSCMyClickBtn * btn) {
        NSLog(@"%@", [gcSelector getSelectedGCIdsStr]);
    };
    //
    TSCMyClickBtn * btn2 = [TSCMyClickBtn buttonWithType:UIButtonTypeSystem];
    [btn2 setTitle:@"-getSelectedGCNameList" forState:UIControlStateNormal];
    btn2.btnClickedListener = ^(TSCMyClickBtn * btn) {
        NSArray * arr = [gcSelector getSelectedGCNameList];
        for (NSString * name in arr) {
            NSLog(@"%@", name);
        }
    };
    //
    TSCMyClickBtn * btn3 = [TSCMyClickBtn buttonWithType:UIButtonTypeSystem];
    [btn3 setTitle:@"+gcNameList2GcNameStr" forState:UIControlStateNormal];
    btn3.btnClickedListener = ^(TSCMyClickBtn * btn) {
        NSArray * arr = [gcSelector getSelectedGCNameList];
        NSLog(@"%@", [TSCMyGCSelector gcNameList2GcNameStr:arr]);
    };
    //
    TSCMyClickBtn * btn4 = [TSCMyClickBtn buttonWithType:UIButtonTypeSystem];
    [btn4 setTitle:@"+gcIds2GcPathNameStr_1" forState:UIControlStateNormal];
    btn4.btnClickedListener = ^(TSCMyClickBtn * btn) {
        NSString * gcIds = [gcSelector getSelectedGCIdsStr];
        NSLog(@"%@", [TSCMyGCSelector gcIds2GcPathNameStr_1:gcIds]);
    };
    //
    TSCMyClickBtn * btn5 = [TSCMyClickBtn buttonWithType:UIButtonTypeSystem];
    [btn5 setTitle:@"+gcIds2GcSingleNameStr_1" forState:UIControlStateNormal];
    btn5.btnClickedListener = ^(TSCMyClickBtn * btn) {
        NSString * gcIds = [gcSelector getSelectedGCIdsStr];
        NSLog(@"%@", [TSCMyGCSelector gcIds2GcSingleNameStr_1:gcIds]);
    };
    //
    TSCLinearLayout * btnPanel = [[TSCLinearLayout alloc]init];
    btnPanel.frame = CGRectMake(50, 200, 300, 300);
//    btnPanel.orientation = LINEAR_LAYOUT_ORIENTATION_HORIZONTAL;
    btnPanel.distribution =  LINEAR_LAYOUT_DISTRIBUTION_FILL_EQUALLY;
    [btnPanel addSubview:btn1];
    [btnPanel addSubview:btn2];
    [btnPanel addSubview:btn3];
    [btnPanel addSubview:btn4];
    [btnPanel addSubview:btn5];
    [self.view addSubview:btnPanel];
    
}

- (void) testMyGCSelector3 {
    // 创建：fv
    UIView * fv = [[UIView alloc]init];
    fv.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:fv];
    
    // 创建：gcSelector
    TSCMyGCSelector * gcSelector = [[TSCMyGCSelector alloc]init];
    //    gcSelector = CGRectMake(50, 50, 400, 400);
    gcSelector.backgroundColor = [UIColor lightGrayColor];
    gcSelector.uiElementHeight = 30.0f;
    gcSelector.uiFontSize = [TSCMyUIUtil getSystemDefaultFont].pointSize; // 13.0f
    //    gcSelector.uiPadding = 10.0f;
    // 绘制界面，并填充数据
    [gcSelector drawUI];
    [gcSelector setupViewData_1];
    [fv addSubview:gcSelector];
    
    
    
    // 约束：fv-位置
    fv.translatesAutoresizingMaskIntoConstraints = NO;
    [NSLayoutConstraint constraintWithItem:fv attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0f constant:0.0f].active = YES;
    [NSLayoutConstraint constraintWithItem:fv attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1.0f constant:0.0f].active = YES;
    // 约束：fv-宽度
    [NSLayoutConstraint constraintWithItem:fv attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0f constant:500.0f].active = YES;
    // 约束：fv-高度
    [NSLayoutConstraint constraintWithItem:fv attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:gcSelector attribute:NSLayoutAttributeTop multiplier:1.0f constant:0.0f].active = YES;
    [NSLayoutConstraint constraintWithItem:fv attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:gcSelector attribute:NSLayoutAttributeBottom multiplier:1.0f constant:0.0f].active = YES;
    
    // 约束：gcSelector-位置
    gcSelector.translatesAutoresizingMaskIntoConstraints = NO;
    [NSLayoutConstraint constraintWithItem:gcSelector attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:fv attribute:NSLayoutAttributeTop multiplier:1.0f constant:0.0f].active = YES;
    [NSLayoutConstraint constraintWithItem:gcSelector attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:fv attribute:NSLayoutAttributeLeft multiplier:1.0f constant:0.0f].active = YES;
    // 约束：gcSelector-宽度
        [NSLayoutConstraint constraintWithItem:gcSelector attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:fv attribute:NSLayoutAttributeWidth multiplier:1.0f constant:0.0f].active = YES;
    // 约束：gcSelector-高度
    NSLog(@"gcSelector 高度：%f", gcSelector.frame.size.height);
//    [NSLayoutConstraint constraintWithItem:gcSelector attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:fv attribute:NSLayoutAttributeRight multiplier:1.0f constant:0.0f].active = YES;
    
    
//    gcSelector.translatesAutoresizingMaskIntoConstraints = NO;
//    [NSLayoutConstraint constraintWithItem:gcSelector attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1.0f constant:0.0f].active = YES;
//    [NSLayoutConstraint constraintWithItem:gcSelector attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeRight multiplier:1.0f constant:0.0f].active = YES;
    
    

}

- (void) testGCSelectorDialog {
    TSCMyGCSelectorDialog * gcsd = [[TSCMyGCSelectorDialog alloc]init];
    gcsd.frame = CGRectMake(50, 40, 800, 30);
//    gcsd
//    gcsd.backgroundColor = [UIColor lightGrayColor];
//    [TSCMyUIUtil setUIRoundBorder:gcsd radius:10.0f borderColor:COLOR_MT borderWidth:1.0f];
//    gcsd.borderStyle = UITextBorderStyleRoundedRect;
    [gcsd initPickerDisplay_1];
    
    [self.view addSubview:gcsd];
}

- (void) testSubviewDeterminSuperview {
    UIView * fv = [[UIView alloc]init];
    fv.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:fv];
    
    UIView * cv1 = [[UIView alloc]init];
    cv1.backgroundColor = [UIColor redColor];
    [fv addSubview:cv1];
    
    UIView * cv2 = [[UIView alloc]init];
    cv2.backgroundColor = [UIColor yellowColor];
    [fv addSubview:cv2];
    
    // 添加约束
    // fv
    fv.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-50-[fv]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(fv)]];
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-50-[fv]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(fv)]];
    // cv1
    cv1.translatesAutoresizingMaskIntoConstraints = NO;
    [fv addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[cv1(cv2)]-0-[cv2(50)]-10-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(cv1, cv2)]];
    [fv addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-20-[cv1(50)]-20-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(cv1)]];
    // cv2
    cv2.translatesAutoresizingMaskIntoConstraints = NO;
    [fv addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-20-[cv2(50)]-20-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(cv2)]];
    
//    [fv systemLayoutSizeFittingSize:UILayoutFittingExpandedSize];
//      fv.sizeToFit;
//    fv.si
}

- (void) testNSLayoutConstraint {
    UIView * fv = [[UIView alloc]init];
    fv.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:fv];
    
    UIView * cv1 = [[UIView alloc]init];
    cv1.backgroundColor = [UIColor blueColor];
    [fv addSubview:cv1];
    
    UIView * cv2 = [[UIView alloc]init];
    cv2.backgroundColor = [UIColor redColor];
    [fv addSubview:cv2];
    
    // 约束
    // fv
    // TODO 不能贴近左上角，而是让使用者自行指定，到底是用frame，还是用constraint
    fv.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-50-[fv]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(fv)]];
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-50-[fv]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(fv)]];
    // cv1
    cv1.translatesAutoresizingMaskIntoConstraints = NO;
    [fv addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[cv1(100)]-10-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(cv1)]];
    [fv addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-10-[cv1(50)]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(cv1)]];
    // cv2
    cv2.translatesAutoresizingMaskIntoConstraints = NO;
    [fv addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[cv2(cv1)]-10-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(cv1, cv2)]];
    [fv addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[cv1][cv2(cv1)]-10-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(cv1, cv2)]];
    
    // 看看fv的约束
    NSArray * cArr = fv.constraints;
    for (NSLayoutConstraint * constraint in cArr) {
        NSLog(@"fv约束：%@", constraint);
    }
    
//    [fv removeConstraint:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[cv2]-10-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(cv2)][0]];
//    [fv addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[cv2]-50-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(cv2)]];
    NSUInteger cNum = cArr.count;
    NSLayoutConstraint * ct = cArr[cNum - 1];
    ct.active = NO;
    [fv addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[cv2]-50-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(cv2)]];    
    
}

- (void) testSubviewOrder {
    UIView * fv = [[UIView alloc]init];
    fv.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:fv];
    
    UIView * cv1 = [[UIView alloc]init];
    cv1.backgroundColor = [UIColor blueColor];
    [fv addSubview:cv1];
    
    UIView * cv2 = [[UIView alloc]init];
    cv2.backgroundColor = [UIColor redColor];
    [fv addSubview:cv2];
    
    // 添加约束
    // fv
    fv.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-50-[fv]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(fv)]];
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-50-[fv]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(fv)]];
    // cv1
    cv1.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[cv1(50)][cv2(50)]-10-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(cv1, cv2)]];
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-10-[cv1(20)]-10-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(cv1)]];
    // cv2
    cv2.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-10-[cv2(20)]-10-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(cv2)]];
    
    NSLog(@"cv1:%p", cv1);
    NSLog(@"cv2:%p", cv2);
    
    for (UIView * cv in fv.subviews) {
        NSLog(@"Get subview: %p", cv);
    }
    
    // 创建一个新的subview
    UIView * cv3 = [[UIView alloc]init];
    cv3.backgroundColor = [UIColor greenColor];
    [fv addSubview:cv3];
    
    // 删除cv2
    [cv2 removeFromSuperview];
    
    // 添加cv3约束
    cv3.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[cv1][cv3(50)]-10-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(cv1, cv3)]];
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-10-[cv3(20)]-10-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(cv3)]];
    
}

- (void) testLinearLayout2_1 {
    // ===== Part I：测试添加、删除子view，及各种padding
    
    TSCLinearLayout * ll = [[TSCLinearLayout alloc]init];
    ll.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:ll];
    
    // 添加约束
    // ll
    ll.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-50-[ll]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(ll)]];
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-50-[ll]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(ll)]];
    
    
    // 添加cv1
    UIView * cv1 = [[UIView alloc]init];
    cv1.frame = CGRectMake(0, 0, 50, 20);
    cv1.backgroundColor = [UIColor blueColor]; // 蓝
    [ll addSubview:cv1];
    
    // 添加cv2
    UIView * cv2 = [[UIView alloc]init];
    cv2.frame = CGRectMake(0, 0, 50, 20);
    cv2.backgroundColor = [UIColor redColor]; // 红
    [ll addSubview:cv2];
    
    // 添加cv3
    UIView * cv3 = [[UIView alloc]init];
    cv3.frame = CGRectMake(0, 0, 50, 20);
    cv3.backgroundColor = [UIColor yellowColor]; // 黄
    [ll addSubview:cv3];
    
    // 添加cv4
    UIView * cv4 = [[UIView alloc]init];
    cv4.frame = CGRectMake(0, 0, 50, 20);
    cv4.backgroundColor = [UIColor greenColor]; // 绿 | 蓝-1 红-2 黄-3 绿-4
    [ll addSubview:cv4];
    
    // 删除：上有下有
    [cv3 removeFromSuperview]; // 蓝-1 红-2 绿-4
    
    // 添加cv5
    UIView * cv5 = [[UIView alloc]init];
    cv5.frame = CGRectMake(0, 0, 50, 20);
    cv5.backgroundColor = [UIColor orangeColor]; // 橘 | 蓝-1 红-2 绿-4 橘-5
    [ll addSubview:cv5];

    // 删除：上有下没有
    [cv5 removeFromSuperview]; // 蓝-1 红-2 绿-4
  
    // 删除：上没有下有
    [cv1 removeFromSuperview]; // 红-2 绿-4
    
    // 删除：上有下没有
    [cv4 removeFromSuperview]; // 红-2
    
    // 删除：上没有下没有
    [cv2 removeFromSuperview];
    
    // ===== Part II：测试先设置父view大小，包括frame设置、AutoLayout设置
    
    // 1 通过frame设置父view
    ll.translatesAutoresizingMaskIntoConstraints = YES;
    ll.frame = CGRectMake(50, 50, 200, 200);
    [ll addSubview:cv1];
    [ll addSubview:cv2];
    [ll addSubview:cv3];
    [ll addSubview:cv4]; // 蓝-1 红-2 黄-3 绿-4
    // 经测试发现，各个子view都排列在左侧，而右侧padding不再遵循10.0f。看来AutoLayout是按照“最大可能性匹配”的，而不必非得满足所有的约束
    
    // 2 通过AutoLayout设置父view宽度占满屏
    ll.translatesAutoresizingMaskIntoConstraints = NO;
    // 注：之前针对父view的约束已经设置过，不用再设置了，只要开启上述开关即可
    
    // 删除原来的约束
    NSArray * llCtArr = [self.view constraints];
    for (NSLayoutConstraint * ct in llCtArr) {
        ct.active = NO;
    }
    
    // 添加新约束：宽度满屏，top顶格，高度随子view数量动态变化
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[ll]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(ll)]];
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[ll]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(ll)]];
}
-(void) testLinearLayout2_2 {
    
    // 测试各种配置属性：padding、横向/纵向、动画
    
    UIView * cv1 = [[UIView alloc]init];
//    cv1.frame = CGRectMake(0, 0, 50, 20);
    cv1.backgroundColor = [UIColor redColor]; // 红
    
    UIView * sv1 = [[UIView alloc]init];
    sv1.frame = CGRectMake(0, 0, 0, 5);
//    sv1.frame = CGRectMake(0, 0, 5, 0);
    sv1.backgroundColor = [UIColor blackColor];
  
    UIView * cv2 = [[UIView alloc]init];
//    cv2.frame = CGRectMake(0, 0, 50, 20);
    cv2.backgroundColor = [UIColor yellowColor]; // 黄
    
    UIView * sv2 = [[UIView alloc]init];
    sv2.frame = CGRectMake(0, 0, 0, 5);
//    sv2.frame = CGRectMake(0, 0, 5, 0);
    sv2.backgroundColor = [UIColor blackColor];
    
    UIView * cv3 = [[UIView alloc]init];
//    cv3.frame = CGRectMake(0, 0, 50, 20);
    cv3.backgroundColor = [UIColor blueColor]; // 蓝
    
    UIView * sv3 = [[UIView alloc]init];
    sv3.frame = CGRectMake(0, 0, 0, 5);
//    sv3.frame = CGRectMake(0, 0, 5, 0);
    sv3.backgroundColor = [UIColor blackColor];
    
    UIView * cv4 = [[UIView alloc]init];
//    cv4.frame = CGRectMake(0, 0, 50, 20);
    cv4.backgroundColor = [UIColor greenColor]; // 绿 | 红-1 黄-2 蓝-3 绿-4

    TSCLinearLayout * ll = [[TSCLinearLayout alloc]init];
    ll.backgroundColor = [UIColor lightGrayColor];
    ll.paddingC2C = 10.0f;
    ll.paddingC2F = 20.0f;
    ll.orientation = LINEAR_LAYOUT_ORIENTATION_VERTICAL;
//    ll.orientation = LINEAR_LAYOUT_ORIENTATION_HORIZONTAL;
//    ll.distribution = LINEAR_LAYOUT_DISTRIBUTION_NONE;
    ll.distribution = LINEAR_LAYOUT_DISTRIBUTION_FILL_EQUALLY;
    [self.view addSubview:ll];
    
    // 设置ll约束
    ll.translatesAutoresizingMaskIntoConstraints = NO;
//    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-50-[ll]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(ll)]];
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-200-[ll]-200-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(ll)]];
//    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-50-[ll]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(ll)]];
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-50-[ll]-50-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(ll)]];
   
    // 每隔一段时间，进行操作，看看动态变化效果
    // 1
    [self testLinearLayout2_exeAfterAWhileWithLL:ll cv:cv1 addOrDelete:1 callback:^{
        [self testLinearLayout2_exeAfterAWhileWithLL:ll cv:sv1 addOrDelete:1 callback:^{
            // 2
            [self testLinearLayout2_exeAfterAWhileWithLL:ll cv:cv2 addOrDelete:1 callback:^{
                [self testLinearLayout2_exeAfterAWhileWithLL:ll cv:sv2 addOrDelete:1 callback:^{
                    // 3
                    [self testLinearLayout2_exeAfterAWhileWithLL:ll cv:cv3 addOrDelete:1 callback:^{
                        [self testLinearLayout2_exeAfterAWhileWithLL:ll cv:sv3 addOrDelete:1 callback:^{
                            // 4
                            [self testLinearLayout2_exeAfterAWhileWithLL:ll cv:cv4 addOrDelete:1 callback:^{
                                // 1
                                [self testLinearLayout2_exeAfterAWhileWithLL:ll cv:cv1 addOrDelete:0 callback:^{
                                    [self testLinearLayout2_exeAfterAWhileWithLL:ll cv:sv1 addOrDelete:0 callback:^{
                                        // 2
                                        [self testLinearLayout2_exeAfterAWhileWithLL:ll cv:cv2 addOrDelete:0 callback:^{
                                            [self testLinearLayout2_exeAfterAWhileWithLL:ll cv:sv2 addOrDelete:0 callback:^{
                                                // 3
                                                [self testLinearLayout2_exeAfterAWhileWithLL:ll cv:cv3 addOrDelete:0 callback:^{
                                                    [self testLinearLayout2_exeAfterAWhileWithLL:ll cv:sv3 addOrDelete:0 callback:^{
                                                        // 4
                                                        [self testLinearLayout2_exeAfterAWhileWithLL:ll cv:cv4 addOrDelete:0 callback:^{
                                                            // do nothing
                                                        }];
                                                    }];
                                                }];
                                            }];
                                        }];
                                    }];
                                }];
                            }];
                        }];
                    }];
                }];
            }];
        }];
    }];
}
- (void) testLinearLayout2_3 {
    // 测试父view占满屏宽度，子view
}
- (void) testLinearLayout2_exeAfterAWhileWithLL:(UIView *)ll cv:(UIView *)cv addOrDelete:(NSInteger)addOrDelete callback:(void(^)())callback {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        CGFloat sleepSecond = 1.0f;
        CGFloat animationSecond = 0.1f;
        
        [NSThread sleepForTimeInterval:sleepSecond];
        
        dispatch_async(dispatch_get_main_queue(), ^{
            if (addOrDelete == 1) {
                // 方法一：不行，用法错啦
//                [UIView animateWithDuration:1 animations:^{
//                    [ll addSubview:cv];
//                }];
                // 方法二：
                [UIView transitionWithView:ll duration:animationSecond options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
                    [ll addSubview:cv];
                } completion:^(BOOL finished) {
                    if (callback) {
                        callback();
                    }
                }];
            } else {
                // 方法一：不行，用法错啦
//                [UIView animateWithDuration:1 animations:^{
//                    [cv removeFromSuperview];
//                }];
                [UIView transitionWithView:ll duration:animationSecond options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
                    [cv removeFromSuperview];
                } completion:^(BOOL finished) {
                    if (callback) {
                        callback();
                    }
                }];
            }
        });
    });
}

- (void) testLinerLayout {
    
//    // 1 添加子view时
//    // 2 删除子view时
//    // 3 被添加到父view时
//    // 4 任意一个子view大小、位置变化时
//    // 5 自身大小、位置变化时
//    // 6 重新设置了影响布局的自定义类属性（比如orientation、whType等）时
//    // 7 TODO 屏幕旋转时
//    // 8 多层时，比如3层，最里层大小变化，最外层是否变化
//    // 9 插入到某个view后
//    // 10 能够在Storyboard中使用
//    
////    // ===== 最新测试代码-frame S
////    
////    // 内部LinerLayout 1
////    
////    UILabel * lb11 = [[UILabel alloc]init];
////    lb11.frame = CGRectMake(0, 0, 100, 50);
////    lb11.text = @"lb11";
////    lb11.backgroundColor = [UIColor blueColor];
////    
////    UILabel * lb12 = [[UILabel alloc]init];
////    lb12.frame = CGRectMake(0, 0, 50, 50);
////    lb12.text = @"lb12";
////    lb12.backgroundColor = [UIColor redColor];
////    
////    TSCLinerLayout * ll1 = [[TSCLinerLayout alloc]init];
////    ll1.layoutWidth = LayoutWHTypeWrapContent;
////    ll1.layoutHeight = LayoutWHTypeWrapContent;
////    ll1.orientation = LinerLayoutOrientationHorizontal;
////    [ll1 addSubview:lb11];
////    [ll1 addSubview:lb12];
////    [self.view addSubview:ll1];
////    
////    // 外部LinerLayout 2
////    UILabel * lb13 = [[UILabel alloc]init];
////    lb13.frame = CGRectMake(0, 0, 100, 50);
////    lb13.text = @"lb13";
////    lb13.backgroundColor = [UIColor yellowColor];
////    
////    UILabel * lb14 = [[UILabel alloc]init];
////    lb14.frame = CGRectMake(0, 0, 150, 50);
////    lb14.text = @"lb14";
////    lb14.backgroundColor = [UIColor purpleColor];
////    
////    TSCLinerLayout * ll2 = [[TSCLinerLayout alloc]init];
//////    ll2.gravity = LayoutGravityRight; // 无效？
//////    ll2.layoutWidth = LayoutWHTypeWrapContent;
//////    ll2.layoutHeight = LayoutWHTypeWrapContent;
////    ll2.layoutWidth = LayoutWHTypeNone;
////    ll2.layoutHeight = LayoutWHTypeNone;
////    ll2.orientation = LinerLayoutOrientationVertical;
////    ll2.backgroundColor = [UIColor grayColor];
////    [ll2 addSubview:ll1];
////    [ll2 addSubview:lb13];
////    [ll2 addSubview:lb14];
////    [self.view addSubview:ll2];
////    
////    ll2.frame = CGRectMake(50, 50, 150, 150);
////    ll2.frame = CGRectMake(50, 50, 200, 200);
////    
////    [ll2 removeFromSuperview]; // 测试是否成功移除observer。removeFromSuperview将不会触发dealloc？！
////    
////    // ===== 最新测试代码-frame E
//    
//    // ===== 最新测试代码-bounds S
//
//    // 内部LinerLayout 1
//
//    UILabel * lb11 = [[UILabel alloc]init];
//    lb11.frame = CGRectMake(0, 0, 100, 50);
//    lb11.text = @"lb11";
//    lb11.backgroundColor = [UIColor blueColor];
//
//    UILabel * lb12 = [[UILabel alloc]init];
//    lb12.frame = CGRectMake(0, 0, 50, 50);
//    lb12.text = @"lb12";
//    lb12.backgroundColor = [UIColor redColor];
//
//    TSCLinerLayout * ll1 = [[TSCLinerLayout alloc]init];
//    ll1.layoutWidth = LayoutWHTypeWrapContent;
//    ll1.layoutHeight = LayoutWHTypeWrapContent;
////    ll1.layoutWidth = LayoutWHTypeNone;
////    ll1.layoutHeight = LayoutWHTypeNone;
//    ll1.orientation = LinerLayoutOrientationHorizontal;
//    [ll1 addSubview:lb11];
//    [ll1 addSubview:lb12];
//    [self.view addSubview:ll1];
//
//    // 外部LinerLayout 2
//    UILabel * lb13 = [[UILabel alloc]init];
//    lb13.frame = CGRectMake(0, 0, 100, 50);
//    lb13.text = @"lb13";
//    lb13.backgroundColor = [UIColor yellowColor];
//
//    UILabel * lb14 = [[UILabel alloc]init];
//    lb14.frame = CGRectMake(0, 0, 150, 50);
//    lb14.text = @"lb14";
//    lb14.backgroundColor = [UIColor purpleColor];
//
//    TSCLinerLayout * ll2 = [[TSCLinerLayout alloc]init];
////    ll2.layoutWidth = LayoutWHTypeWrapContent;
////    ll2.layoutHeight = LayoutWHTypeWrapContent;
//    ll2.layoutWidth = LayoutWHTypeNone;
//    ll2.layoutHeight = LayoutWHTypeNone;
//    ll2.orientation = LinerLayoutOrientationVertical;
//    ll2.gravity = LayoutGravityRight; // 修改默认的左侧对齐，改为右侧对齐
//    ll2.backgroundColor = [UIColor grayColor];
//    [ll2 addSubview:ll1];
//    [ll2 addSubview:lb13];
//    [ll2 addSubview:lb14];
//    [self.view addSubview:ll2];
//    
//    
////    ll2.bounds = CGRectMake(0, 0, 150, 150);
//    ll2.bounds = CGRectMake(0, 0, 200, 200);
//    ll2.center = CGPointMake(150, 150);
//    
//    
//    // ===== 最新测试代码-bounds E
//    
//    
//    
//    // 测试最左Storyboard
//    //    TSCLinerLayout * ll = (TSCLinerLayout * )[self.view viewWithTag:11];
//    //    ll.orientation = LinerLayoutOrientationHorizontal;
//    //    ll.layoutWidth = LayoutWHTypeNone;
//    //    ll.layoutHeight = LayoutWHTypeNone;
//    ////    ll.gravity = (LayoutGravityLeft);
//    ////    ll.gravity = (LayoutGravityCenterHorizontal);
//    ////    ll.gravity = (LayoutGravityRight);
//    ////    ll.gravity = (LayoutGravityTop);
//    ////    ll.gravity = (LayoutGravityCenterVertical);
//    ////    ll.gravity = (LayoutGravityBottom);
//    ////    ll.gravity = (LayoutGravityCenter);
//    ////    ll.gravity = (LayoutGravityBottom|LayoutGravityCenterHorizontal);
//    ////    ll.gravity = (LayoutGravityRight|LayoutGravityCenterVertical);
//    
//    
//    //    // 1
//    //    TSCLinerLayout * ll1 = [[TSCLinerLayout alloc]init];
//    //    ll1.backgroundColor = COLOR_MT_DIALOG_MODAL;
//    //    ll1.frame = CGRectMake(100, 100, 0, 0);
//    //    ll1.orientation = vertical;
//    //    ll1.layoutWidth = wrap_content;
//    //    ll1.layoutHeight = wrap_content;
//    //
//    //    for (UIView * sv in self.view.subviews) {
//    //        [sv removeFromSuperview];
//    //        [ll1 addSubview:sv];
//    //    }
//    //
//    //    [self.view addSubview:ll1];
//    //
//    //    // 2
//    //    TSCLinerLayout * ll2= [[TSCLinerLayout alloc]init];
//    //    ll2.frame = CGRectMake(100, 200, 0, 0);
//    //    ll2.orientation = horizontal;
//    //    ll2.layoutWidth = wrap_content;
//    //    ll2.layoutHeight = wrap_content;
//    //
//    //    UILabel * lb3 = [[UILabel alloc]init];
//    //    lb3.frame = CGRectMake(0, 0, 80, 20);
//    //    lb3.backgroundColor = [UIColor blueColor];
//    //    lb3.text = @"label 3";
//    //    [ll2 addSubview:lb3];
//    //
//    //    UILabel * lb4 = [[UILabel alloc]init];
//    //    lb4.frame = CGRectMake(0, 0, 80, 20);
//    //    lb4.backgroundColor = [UIColor yellowColor];
//    //    lb4.text = @"label 4";
//    //    [ll2 addSubview:lb4];
//    //
//    ////    [self.view addSubview:ll2];
//    //    [ll1 addSubview:ll2];
//    
//    
//    
//    //    TSCLinerLayout * ll1 = (TSCLinerLayout *) [self.view viewWithTag:1];
//    ////    ll1.backgroundColor = COLOR_MT_DIALOG_MODAL;
//    //
//    //    TSCLinerLayout * ll2 = (TSCLinerLayout *) [self.view viewWithTag:2];
//    ////    ll2.backgroundColor = COLOR_MT_DIALOG_MODAL;
//    //
//    //
//    //    TSCLinerLayout * ll3 = (TSCLinerLayout *) [self.view viewWithTag:3];
//    //
//    ////    [ll1 removeFromSuperview];
//    ////    [ll2 removeFromSuperview];
//    
//    
//    // 1 是上面的小区域
////    TSCLinerLayout * ll1 = (TSCLinerLayout *) [self.view viewWithTag:1];
//    //    [ll1 removeFromSuperview];
//    //    ll1.layoutWidth = LayoutWHTypeWrapContent;
//    //    ll1.layoutHeight = LayoutWHTypeWrapContent;
//    //    ll1.orientation = LinerLayoutOrientationHorizontal;
//    //    ll1.gravity = (LayoutGravityLeft);
//    //    ll1.gravity = (LayoutGravityCenterHorizontal);
//    //    ll1.gravity = (LayoutGravityRight);
//    //    ll1.gravity = (LayoutGravityTop);
//    //    ll1.gravity = (LayoutGravityCenterVertical);
//    //    ll1.gravity = (LayoutGravityBottom);
//    //    ll1.gravity = (LayoutGravityCenter);
//    //    ll1.gravity = (LayoutGravityBottom|LayoutGravityCenterHorizontal);
////    ll1.gravity = (LayoutGravityRight|LayoutGravityCenterVertical);
//    
//    // 2 是下面的大区域
////    TSCLinerLayout * ll2 = (TSCLinerLayout *) [self.view viewWithTag:2];
//    //    [ll2 removeFromSuperview];
//    //    ll2.layoutWidth = LayoutWHTypeWrapContent;
//    //    ll2.layoutHeight = LayoutWHTypeWrapContent;
//    //    ll2.orientation = LinerLayoutOrientationVertical;
//    //    ll2.gravity = (LayoutGravityLeft);
//    //    ll2.gravity = (LayoutGravityCenterHorizontal);
//    //    ll2.gravity = (LayoutGravityRight);
//    //    ll2.gravity = (LayoutGravityTop);
//    //    ll2.gravity = (LayoutGravityCenterVertical);
//    //    ll2.gravity = (LayoutGravityBottom);
//    //    ll2.gravity = (LayoutGravityCenter);
////    ll2.gravity = (LayoutGravityBottom|LayoutGravityCenterHorizontal);
//    //    ll2.gravity = (LayoutGravityRight|LayoutGravityCenterVertical);
//    //    ll2.frame = CGRectMake(100, 200, 0, 0);
//    
//    //    UILabel * lb1 = (UILabel * )[ll1 viewWithTag:11];
//    //    lb1.bounds = CGRectMake(0, 0, 100, 100);
//    //    
//    //    [ll1 removeFromSuperview];
}

- (void) testSpinner {
    // 添加spinner
    // 测试1：frame、center；
    // 测试2：数据多少
    // 测试3：0层、1层；
    // 测试4：setFrame在addSubview之前、之后；
    //
    // 测试5：多次添加数据
    // 测试6：延迟添加数据
    
    // 0 层
    TSCMySpinner * spCity = [[TSCMySpinner alloc] init];
    spCity.frame = CGRectMake(0, 0, UI_SCREEN_WIDTH - 50, 30);
    spCity.center = CGPointMake(UI_SCREEN_WIDTH / 2, 300);
    [self.view addSubview:spCity];
    
    // 修改大小、位置
    spCity.frame = CGRectMake(0, 0, UI_SCREEN_WIDTH - 150, 50);
    spCity.center = CGPointMake(UI_SCREEN_WIDTH / 2,  150);
    
    //    // 1层
    //    TSCMySpinner2 * spCity = [[TSCMySpinner2 alloc]init];
    //    spCity.frame = CGRectMake(0, 0, UI_SCREEN_WIDTH - 50, 30);
    //
    //    UIView * pv = [[UIView alloc]init];
    //    pv.frame = CGRectMake(0, 0, UI_SCREEN_WIDTH - 50, 30);
    //    pv.center = CGPointMake(UI_SCREEN_WIDTH / 2, 100);
    //
    //    [pv addSubview:spCity];
    //    [self.view addSubview: pv];
    
    //    // 2层
    //    TSCMySpinner2 * spCity = [[TSCMySpinner2 alloc]init];
    //    spCity.frame = CGRectMake(0, 0, UI_SCREEN_WIDTH - 50, 30);
    //
    //    UIView * pv1 = [[UIView alloc]init];
    //    pv1.frame = CGRectMake(0, 0, UI_SCREEN_WIDTH - 50, 30);
    //
    //    UIView * pv2 = [[UIView alloc]init];
    //    pv2.frame = CGRectMake(0, 0, UI_SCREEN_WIDTH - 50, 30);
    //    pv2.center = CGPointMake(UI_SCREEN_WIDTH / 2, 100);
    //
    //    [pv1 addSubview:spCity];
    //    [pv2 addSubview:pv1];
    //    [self.view addSubview: pv2];

//    // 添加数据源
//    [spCity prepareData_P1:^{
//        spCity.dataArray = [NSMutableArray arrayWithObjects:
//                            @"1",
//                            @"2",
//                            @"3",
//                            @"4",
//                            @"5",
//                            @"6",
//                            @"7",
//                            @"8",
//                            nil];
//    } completionHandler:^{
//        [spCity applyData];
//    }];
    
// 延迟添加数据源
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    [NSThread sleepForTimeInterval:2];

    dispatch_async(dispatch_get_main_queue(), ^{
        [spCity prepareData_P1:^{
            [spCity.dataArray addObject:@"11"];
            [spCity.dataArray addObject:@"12"];
            [spCity.dataArray addObject:@"13"];
            [spCity.dataArray addObject:@"14"];
        } completionHandler:^{
            [spCity applyData];
        }];
    });
});
    
}

- (void) testAddSubviewToLinearLayout {
    TSCLinearLayout * ll = [[TSCLinearLayout alloc]init];
    ll.orientation = LINEAR_LAYOUT_ORIENTATION_VERTICAL;
    ll.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:ll];
    
    UIView * sv1 = [[UIView alloc]init];
    sv1.frame = CGRectMake(0, 0, 50, 50);
    sv1.backgroundColor = [UIColor redColor];
    [ll addSubview:sv1];
    
    UIView * sv2 = [[UIView alloc]init];
    sv2.frame = CGRectMake(0, 0, 50, 50);
    sv2.backgroundColor = [UIColor blueColor];
    [ll addSubview:sv2];
    
    UIView * sv3 = [[UIView alloc]init];
    sv3.frame = CGRectMake(0, 0, 50, 50);
    sv3.backgroundColor = [UIColor yellowColor];
    [ll addSubview:sv3];
    
    // 约束
    // ll
    ll.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:ll attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0f constant:0.0f]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:ll attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1.0f constant:0.0f]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:ll attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeWidth multiplier:(1.0f / 2.0f) constant:0.0f]];
//    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:ll attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeHeight multiplier:1.0f constant:0.0f]];

}

- (void) testAddSubviewToSuperviewSeperate {
//    UIView * fv = [[UIView alloc]init];
    TSCLinearLayout * fv = [[TSCLinearLayout alloc]init];
    fv.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:fv];
    
    UIView * sv1 = [[UIView alloc]init];
    sv1.frame = CGRectMake(0, 0, 0, 50);
    sv1.backgroundColor = [UIColor redColor];
    [fv addSubview:sv1];
    
    // 约束
    // fv
    fv.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:fv attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0f constant:0.0f]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:fv attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1.0f constant:0.0f]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:fv attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeWidth multiplier:(1.0f / 2.0f) constant:0.0f]];
    // sv1
//    sv1.translatesAutoresizingMaskIntoConstraints = NO;
    
    // 方法一：
//    [fv addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[sv1]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(sv1)]];
//    [fv addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[sv1(50)]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(sv1)]];
    
    // 方法二：
//    [fv addConstraint:[NSLayoutConstraint constraintWithItem:sv1 attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:fv attribute:NSLayoutAttributeLeft multiplier:1.0f constant:0.0f]];
//    [fv addConstraint:[NSLayoutConstraint constraintWithItem:sv1 attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:fv attribute:NSLayoutAttributeTop multiplier:1.0f constant:0.0f]];
//    [fv addConstraint:[NSLayoutConstraint constraintWithItem:sv1 attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:fv attribute:NSLayoutAttributeRight multiplier:1.0f constant:0.0f]];
//    [fv addConstraint:[NSLayoutConstraint constraintWithItem:sv1 attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:fv attribute:NSLayoutAttributeBottom multiplier:1.0f constant:0.0f]];
//    [fv addConstraint:[NSLayoutConstraint constraintWithItem:sv1 attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0f constant:50.0f]];
    
    // 上述两个方法等效。由此可见，仅通过约束指定父view的宽，子view与父view同宽，并靠子view自身的高度来撑开父view的高度，是没有问题的。
    
    // 方法三：把fv换成LiearLayout。证实可以！
    // 方法四：把fv换成LiearLayout，且通过设置sv.frame，来控制fv高度。可以！
    
    NSArray * fvCtArr = [fv constraints];
    for (NSLayoutConstraint * ct in fvCtArr) {
        NSLog(@"ct:%@", ct);
    }
    
}

-(void) testMyDialog0 {
//    TSCMyDialog * dialog = [[TSCMyDialog alloc]initWithViewController:self Title:@"标题" processingMessage:@"正在提交..." message:@"这个故事一定很好听！" leftBtn:@"左" leftBtnBlock:^(UIButton *btn, TSCMyDialog *dialog) {
//        NSLog(@"左按钮");
//    } middleBtn:@"中" middleBtnBlock:^(UIButton *btn, TSCMyDialog *dialog) {
//        NSLog(@"中按钮");
//    } rightBtn:@"右" rightBtnBlock:^(UIButton *btn, TSCMyDialog *dialog) {
//        NSLog(@"右按钮");
//    }];
//    [dialog show];
}

- (void) testMyDialog {
//    TSCMyDialog2 *dialog = [[TSCMyDialog2 alloc]initWithViewController:self Title:@"标题" processingMessage:@"正在处理..." message:@"这个故事一定很好听！" leftBtn:@"左" leftBtnBlock:nil middleBtn:@"中" middleBtnBlock:nil rightBtn:@"右" rightBtnBlock:nil];
//    [dialog show];
//
////    UIImageView * customView = [[UIImageView alloc]init];
////    customView.image = [UIImage imageNamed:@"ic_app_logo_96x96.png"];
////    customView.frame = CGRectMake(0, 0, 50, 50);
//    
////    UIButton * customView = [UIButton buttonWithType:UIButtonTypeSystem];
////    [customView setTitle:@"自定义按钮" forState:UIControlStateNormal];
////    customView.frame = CGRectMake(0, 0, 50, 50);
//    
//  
    // 添加一个按钮，用来显示dialog
    TSCMyClickBtn * btnShow = [[TSCMyClickBtn alloc]init];
    [btnShow setTitle:@"显示" forState:UIControlStateNormal];
    btnShow.backgroundColor = [UIColor blueColor];
    btnShow.frame = CGRectMake(50, 50, 100, 50);
    btnShow.btnClickedListener = ^(TSCMyClickBtn * button) {
        TSCMyGCSelector * gcSelector = [[TSCMyGCSelector alloc]init];
        gcSelector.maxRows = 3;
        [gcSelector drawUI];
        [gcSelector setupViewData_1];
        
        TSCMyDialog * dialog = [[TSCMyDialog alloc]init];
        dialog.textSize = 20.0f;
        dialog.titleText = @"标题";
        dialog.processingMsgText = @"正在处理...";
        dialog.msgText = @"这个故事一定很好听！";
        dialog.customView = gcSelector;
        dialog.leftBtnText = @"左";
        dialog.middleBtnText = @"中";
        dialog.rightBtnText = @"右";
        dialog.leftBtnOnClickListener = ^(UIButton * btn, TSCMyDialog * dialog) {
            NSLog(@"左按钮：%@，被点击了", btn);
        };
        dialog.middleBtnOnClickListener = ^(UIButton * btn, TSCMyDialog * dialog) {
            NSLog(@"中按钮：%@，被点击了", btn);
        };
        dialog.rightBtnOnClickListener = ^(UIButton * btn, TSCMyDialog * dialog) {
            NSLog(@"右按钮：%@，被点击了", btn);
        };
        
        [dialog show];
    };
    [self.view addSubview:btnShow];
    
}

- (void) testConstraint {
    // 测试，如果刚刚创建的约束，没有指定.active，是否生效
    UIView * fv = [[UIView alloc]init];
    fv.backgroundColor = [UIColor lightGrayColor];
    fv.frame = CGRectMake(50, 50, 300, 300);
    [self.view addSubview:fv];
    
    UIView * sv1=  [[UIView alloc]init];
    sv1.backgroundColor = [UIColor yellowColor];
    [fv addSubview:sv1];
    
    // 约束
    // sv1
    sv1.translatesAutoresizingMaskIntoConstraints = NO;
    NSArray * ctArr1 = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-50-[sv1]-50-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(sv1)];
    NSArray * ctArr2 = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-50-[sv1]-50-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(sv1)];
//    [NSLayoutConstraint activateConstraints:ctArr1];
//    [NSLayoutConstraint activateConstraints:ctArr2];
    
    // 试验证明，如果不设置.active = YES，该约束是不会生效的
}

- (void) testDialogConstraintsForWidthAndHeight {
    UIView * dialog = [[UIView alloc]init];
    dialog.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:dialog];
    
    dialog.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:dialog attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0f constant:0.0f]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:dialog attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1.0f constant:0.0f]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:dialog attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeWidth multiplier:(3.0f / 4.0f) constant:0.0f]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:dialog attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeHeight multiplier:(1.0f / 2.0f) constant:0.0f]];
}

- (void) testSubviewExtendsLinearLayoutSuperview {
    TSCLinearLayout * dialog = [[TSCLinearLayout alloc]init];
    dialog.paddingC2F = 15.0f;
    dialog.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:dialog];
    
    dialog.translatesAutoresizingMaskIntoConstraints = NO;
    
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:dialog attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0f constant:0.0f]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:dialog attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1.0f constant:0.0f]];
    
    
    UIView * sv1=  [[UIView alloc]init];
    sv1.backgroundColor = [UIColor yellowColor];
    [dialog addSubview:sv1];
    
    sv1.translatesAutoresizingMaskIntoConstraints = NO;
//    [dialog addConstraint:[NSLayoutConstraint constraintWithItem:sv1 attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeWidth multiplier:(3.0f / 4.0f) constant:0.0f]];
//    [dialog addConstraint:[NSLayoutConstraint constraintWithItem:sv1 attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeHeight multiplier:(1.0f / 4.0f) constant:0.0f]];
    
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:sv1 attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeWidth multiplier:(3.0f / 4.0f) constant:0.0f]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:sv1 attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeHeight multiplier:(1.0f / 4.0f) constant:0.0f]];
    
    // 以下dialog都为LinearLayout
    // 设置dialog x/y中心，设置subview.frame：可以
    // 设置dialog x/y中心，设置dialog宽度、高度约束[设置在在self.view]：可以
    // 设置dialog x/y中心，设置dialog宽度约束[设置在self.view]，设置subview.frame.height：不行
    // 设置dialog x/y中心，设置subview宽度、高度约束[设置在self.view]：可以
    // 设置dialog x/y中心，设置subview宽度、高度约束[设置在dialog]：运行时错误。看terminal的报错信息，说明withItem和toItem都必须在constraintWithItem()方法的调用者内部
}

- (void) testDialogReplaceContent {
    TSCMyDialog * dialog = [[TSCMyDialog alloc]init];
    dialog.titleText = @"第一个dialog";
    dialog.processingMsgText = @"正在提交...";
    dialog.leftBtnText = @"左";
    dialog.rightBtnText = @"右";
    [dialog show];
    
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [NSThread sleepForTimeInterval:1];
        
        dispatch_async(dispatch_get_main_queue(), ^{
            TSCMyGCSelector * gcSelector = [[TSCMyGCSelector alloc]init];
            gcSelector.maxRows = 3;
            [gcSelector drawUI];
            [gcSelector setupViewData_1];
            
            TSCMyDialog * d2 = [[TSCMyDialog alloc]init];
            d2.titleText = @"标题";
            d2.processingMsgText = @"正在处理...";
            d2.msgText = @"这个故事一定很好听！";
            d2.customView = gcSelector;
            d2.leftBtnText = @"左";
            d2.middleBtnText = @"中";
            d2.rightBtnText = @"右";
            d2.leftBtnOnClickListener = ^(UIButton * btn, TSCMyDialog * dialog) {
                NSLog(@"左按钮：%@，被点击了", btn);
            };
            d2.middleBtnOnClickListener = ^(UIButton * btn, TSCMyDialog * dialog) {
                NSLog(@"中按钮：%@，被点击了", btn);
            };
            d2.rightBtnOnClickListener = ^(UIButton * btn, TSCMyDialog * dialog) {
                NSLog(@"右按钮：%@，被点击了", btn);
            };
            [dialog replaceContentViewWithOtherDialog:d2];
        });
    });
}


- (void) testMyClickBtn {
        TSCMyClickBtn * btn = [TSCMyClickBtn buttonWithType:UIButtonTypeSystem];
        btn.frame = CGRectMake(50, 50, 200, 200);
        btn.backgroundColor = COLOR_MT;
        [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [btn setTitle:@"测试按钮" forState:UIControlStateNormal];
        btn.btnClickedListener = ^(TSCMyClickBtn *button) {
            NSLog(@"回调被执行！");
        };
        [self.view addSubview:btn];
}

- (void) testUploadPicDialog {
    // 创建customView
    UIImageView * iv = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"ic_sample_logo_320x320.png"]];
    UIView * fv = [[UIView alloc]init];
    fv.backgroundColor = [UIColor lightGrayColor];
    [fv addSubview:iv];
    
    // 约束
    // iv
    iv.translatesAutoresizingMaskIntoConstraints = NO;
    [fv addConstraint:[NSLayoutConstraint constraintWithItem:iv attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:fv attribute:NSLayoutAttributeCenterX multiplier:1.0f constant:0.0f]];
    [fv addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-50-[iv]-50-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(iv)]];
    
    // 创建图片选择器
    TSCMyUploadPicDialog * upd = [[TSCMyUploadPicDialog alloc]init];
    upd.frame = CGRectMake(50, 50, 800, 50);
//    upd.textSize = 20.0f;
    upd.title = @"选择商品图片";
    upd.bodyView = fv;
    upd.maxPhotoPickNum = 3;
    // （1）系统自带
//    upd.imagePickerControllerDidCancel = ^(UIImagePickerController * picker) {
//        // 注：系统不会自动关闭，需要手动关闭
//        [picker dismissViewControllerAnimated:YES completion:nil];
//    };
//    upd.imagePickerControllerDidFinishPickingMediaWithInfo = ^(UIImagePickerController * picker, NSDictionary * info) {
//        
//        NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
//        UIImage *originalImage, *editedImage, *imageToSave;
//        
//        // Handle a still image capture
//        if (CFStringCompare ((CFStringRef) mediaType, kUTTypeImage, 0)
//            == kCFCompareEqualTo) {
//            
//            editedImage = (UIImage *) [info objectForKey:
//                                       UIImagePickerControllerEditedImage];
//            originalImage = (UIImage *) [info objectForKey:
//                                         UIImagePickerControllerOriginalImage];
//            
//            if (editedImage) {
//                imageToSave = editedImage;
//            } else {
//                imageToSave = originalImage;
//            }
//            
//            // Save the new image (original or edited) to the Camera Roll
//            UIImageWriteToSavedPhotosAlbum (imageToSave, nil, nil , nil);
//        }
//        
//        //    // Handle a movie capture
//        //    if (CFStringCompare ((CFStringRef) mediaType, kUTTypeMovie, 0)
//        //        == kCFCompareEqualTo) {
//        //
//        //        NSString *moviePath = [[info objectForKey:
//        //                                UIImagePickerControllerMediaURL] path];
//        //
//        //        if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)) {
//        //            UISaveVideoAtPathToSavedPhotosAlbum (
//        //                                                 moviePath, nil, nil, nil);
//        //        }
//        //    }
//        
//        // 注：系统不会自动关闭，需要手动关闭
//        [picker dismissViewControllerAnimated:YES completion:nil];
//    };
    
//    // （2）第三方
//    upd.elcImagePickerControllerDidCancel = ^(ELCImagePickerController * picker) {
//        // 注：系统不会自动关闭，需要手动关闭
//        [picker dismissViewControllerAnimated:YES completion:nil];
//    };
//    upd.elcImagePickerControllerDidFinshPickingMediaWithInfo = ^(ELCImagePickerController * picker, NSArray * infoArr) {
//        for (NSDictionary * info in infoArr) {
//            // TODO 测试选择相片的顺序
////            for (NSString * key in [info allKeys]) {
////                NSLog(@"info:[%@]%@", key, [info valueForKey:key]);
////            }
//            // 注：key至少包括：
//            // 1 UIImagePickerControllerOriginalImage
//            // 2 UIImagePickerControllerMediaType
//            // 3 UIImagePickerControllerReferenceURL
//            // 可能还包含：
//            // 1（如果编辑过图片的话）UIImagePickerControllerEditedImage
//            
//            
//            NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
//            UIImage *originalImage, *editedImage, *imageToSave;
//            
//            // Handle a still image capture
//            if ([mediaType isEqualToString:ALAssetTypePhoto]) {
//                
//                editedImage = (UIImage *) [info objectForKey:UIImagePickerControllerEditedImage];
//                originalImage = (UIImage *) [info objectForKey:UIImagePickerControllerOriginalImage];
//                
//                if (editedImage) {
//                    imageToSave = editedImage;
//                } else {
//                    imageToSave = originalImage;
//                }
//                
//                // Save the new image (original or edited) to the Camera Roll
//                UIImageWriteToSavedPhotosAlbum (imageToSave, nil, nil , nil);
//                
//            }
//            
//            // TODO 如果要使用第三方相片选择器选择视频文件，可能需要修改if判断逻辑
//            //    // Handle a movie capture
//            //    if (CFStringCompare ((CFStringRef) mediaType, kUTTypeMovie, 0)
//            //        == kCFCompareEqualTo) {
//            //
//            //        NSString *moviePath = [[info objectForKey:
//            //                                UIImagePickerControllerMediaURL] path];
//            //
//            //        if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)) {
//            //            UISaveVideoAtPathToSavedPhotosAlbum (
//            //                                                 moviePath, nil, nil, nil);
//            //        }
//            //    }
//        }
//        
//        // 注：系统不会自动关闭，需要手动关闭
//        [picker dismissViewControllerAnimated:YES completion:nil];
//    };
    
    // （3）整合
    upd.myImagePickerControllerDidCancel = ^(UINavigationController * picker) {
        // 注：系统不会自动关闭，需要手动关闭
        [picker dismissViewControllerAnimated:YES completion:nil];
    };
    upd.myImagePickerControllerDidFinishPickingMediaWithInfo = ^(UINavigationController * picker, NSArray * infoArr) {
        for (NSDictionary * info in infoArr) {
            // TODO 测试选择相片的顺序
//            for (NSString * key in [info allKeys]) {
//                NSLog(@"info:[%@]%@", key, [info valueForKey:key]);
//            }
            // 注：key至少包括：
            // 1 UIImagePickerControllerOriginalImage
            // 2 UIImagePickerControllerMediaType
            // 3 UIImagePickerControllerReferenceURL
            // 可能还包含：
            // 1（如果编辑过图片的话）UIImagePickerControllerEditedImage
            
            NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
            UIImage *originalImage, *editedImage, *imageToSave;
            
            // Handle a still image capture
            if (
                // 系统自带：当返回的相片为此类型时，表示是通过系统自带的拍照功能获得的相片（一张）
                (CFStringCompare ((CFStringRef) mediaType, kUTTypeImage, 0) == kCFCompareEqualTo)
                ||
                 // ELC：当返回的相片为此类型时，表示是通过ELC从相册中选择的相片（一张，或者多张）
                [mediaType isEqualToString:ALAssetTypePhoto]
                ) {
                editedImage = (UIImage *) [info objectForKey:UIImagePickerControllerEditedImage];
                originalImage = (UIImage *) [info objectForKey:UIImagePickerControllerOriginalImage];
                
                if (editedImage) {
                    imageToSave = editedImage;
                } else {
                    imageToSave = originalImage;
                }
                
                // 测试一：保存到相册
                // Save the new image (original or edited) to the Camera Roll
//                UIImageWriteToSavedPhotosAlbum (imageToSave, nil, nil , nil);
                
//                // 测试二：保存到app目录
//                // 注：这里for循环中多次生成imageFilePath的将同名（因为时间间隔太短了），导致最后一次循环的文件覆盖了之前全部已经成功保存的文件。这个例子不好
//                NSString * imageFilePath = [TSCMyUtil makeFile:FileTypeImgPic fileName:nil overwrite:NO];
//                [UIImageJPEGRepresentation(imageToSave, 1.0) writeToFile:imageFilePath atomically:YES];
                
//                // 测试三：根据选择的原图，生成缩略图
//                MyFileUIView * result = [TSCMyImageUtil generateThumbnailWithOriginalImage:imageToSave];
//                if (result) {
//                    NSLog(@"Done! File path: %@", result.filePath);
//                } else {
//                    NSLog(@"Error!");
//                }
                
                // 测试四：UIImagePickerControllerReferenceURL
                NSURL * url = [info objectForKey:@"UIImagePickerControllerReferenceURL"];
                ALAssetsLibrary * library = [[ALAssetsLibrary alloc]init];
                [library assetForURL:url resultBlock:^(ALAsset *asset) {
                    ALAssetRepresentation *representation = [asset defaultRepresentation];
                    
                    CGFloat scale = representation.scale;
                    UIImageOrientation orientation = (UIImageOrientation)representation.orientation; // 默认1.0f
                    CGImageRef imgRef = representation.fullResolutionImage; // 默认0
                    UIImage * imageFromAsset = [[UIImage alloc]initWithCGImage:imgRef scale:scale orientation:orientation];
                    
                    // UIImagePickerControllerReferenceURL->ALAsset->UIImage->UIImageJPEGRepresentation()->图片文件
                    // 以下所有测试，都是JPG保存为JPG
                    // 原图：14.7Mb
                    // 1.0 - 22.2Mb
                    // 0.9 - 8.3Mb()
                    // 0.8 - 6.9Mb
                    // 0.7 - 6Mb
                    // 0.6 - 4.3Mb
                    // 0.5 - 3.3Mb
                    // 0.4 - 2.4Mb
                    // 0.3 - 1.7Mb
                    // 0.2 - 1.4Mb
                    // 0.1 - 1.2Mb
                    // 原图：505Kb
                    // 1.0 - 2.2Mb
                    // 0.9 - 944Kb
                    // 0.8 - 803Kb
                    // 0.7 - 706Kb
                    // 0.6 - 569Kb
                    // 0.5 - 470Kb()
                    // 0.4 - 384Kb
                    // 0.3 - 308Kb
                    // 0.2 - 211Kb
                    // 0.1 - 178Kb
                    // 原图：157Kb
                    // 1.0 - 595
                    // 0.9 - 226
                    // 0.8 - 176
                    // 0.7 - 159
                    // 0.6 - 124()
                    // 0.5 - 110
                    // 0.4 - 83
                    // 0.3 - 58
                    // 0.2 - 48
                    // 0.1 - 44
//                    NSString * imgPath = [TSCMyUtil makeFile:FileTypeImgTemp fileName:@"10.jpg" overwrite:YES];
//                    [UIImageJPEGRepresentation(imageFromAsset, 1.0f) writeToFile:imgPath atomically:YES];
//                    imgPath = [TSCMyUtil makeFile:FileTypeImgTemp fileName:@"09.jpg" overwrite:YES];
//                    [UIImageJPEGRepresentation(imageFromAsset, 0.9f) writeToFile:imgPath atomically:YES];
//                    imgPath = [TSCMyUtil makeFile:FileTypeImgTemp fileName:@"08.jpg" overwrite:YES];
//                    [UIImageJPEGRepresentation(imageFromAsset, 0.8f) writeToFile:imgPath atomically:YES];
//                    imgPath = [TSCMyUtil makeFile:FileTypeImgTemp fileName:@"07.jpg" overwrite:YES];
//                    [UIImageJPEGRepresentation(imageFromAsset, 0.7f) writeToFile:imgPath atomically:YES];
//                    imgPath = [TSCMyUtil makeFile:FileTypeImgTemp fileName:@"06.jpg" overwrite:YES];
//                    [UIImageJPEGRepresentation(imageFromAsset, 0.6f) writeToFile:imgPath atomically:YES];
//                    imgPath = [TSCMyUtil makeFile:FileTypeImgTemp fileName:@"05.jpg" overwrite:YES];
//                    [UIImageJPEGRepresentation(imageFromAsset, 0.5f) writeToFile:imgPath atomically:YES];
//                    imgPath = [TSCMyUtil makeFile:FileTypeImgTemp fileName:@"04.jpg" overwrite:YES];
//                    [UIImageJPEGRepresentation(imageFromAsset, 0.4f) writeToFile:imgPath atomically:YES];
//                    imgPath = [TSCMyUtil makeFile:FileTypeImgTemp fileName:@"03.jpg" overwrite:YES];
//                    [UIImageJPEGRepresentation(imageFromAsset, 0.3f) writeToFile:imgPath atomically:YES];
//                    imgPath = [TSCMyUtil makeFile:FileTypeImgTemp fileName:@"02.jpg" overwrite:YES];
//                    [UIImageJPEGRepresentation(imageFromAsset, 0.2f) writeToFile:imgPath atomically:YES];
//                    imgPath = [TSCMyUtil makeFile:FileTypeImgTemp fileName:@"01.jpg" overwrite:YES];
//                    [UIImageJPEGRepresentation(imageFromAsset, 0.1f) writeToFile:imgPath atomically:YES];

                    // 测试五：imgaeToSave和通过ALAsset得到的UIImage，大小是否一致？（答案：是一致的）
                    // 原图：157Kb
                    // imageToSave：595Kb
                    // imageFromAsset：595Kb
//                    NSString * imgPath = [TSCMyUtil makeFile:FileTypeImgTemp fileName:@"aa.jpg" overwrite:YES];
//                    [UIImageJPEGRepresentation(imageToSave, 1.0f) writeToFile:imgPath atomically:YES];
//                    imgPath = [TSCMyUtil makeFile:FileTypeImgTemp fileName:@"bb.jpg" overwrite:YES];
//                    [UIImageJPEGRepresentation(imageFromAsset, 1.0f) writeToFile:imgPath atomically:YES];
                    
                    // 测试六：保存为PNG，是否就是无损的？
                    // 以下测试为PNG保存为PNG
                    // 注：别测了，因为从七牛下载的基本上都是JPG，测试PNG没有意义
                    
                    // 测试七：scale和orientation
                    // 默认scale：1.0f
                    // 默认orientation：0
//                    NSLog(@"scale: %f", scale);
//                    NSLog(@"orientation: %li", (long)orientation);
                    
                    // 测试八：为IOS设计的MyImageUtil.getThumbnailWithOriginalImage()
                    // 只缩放尺寸，不缩放大小：
                    // 原图：157Kb；缩略图：332Kb
                    // 原图：505Kb；缩略图：429Kb
                    // 尺寸、大小都缩放：
                    // 原图：157Kb；缩略图：32Kb
                    // 原图：505Kb；缩略图：59Kb
                     NSString * imgPath = [TSCMyUtil makeFile:FileTypeImgTemp fileName:@"100.jpg" overwrite:YES];
                    [[TSCMyImageUtil getThumbnailWithOriginalImage_1:imageFromAsset] writeToFile:imgPath atomically:YES];
                    
                } failureBlock:^(NSError *error) {
                    NSLog(@"通过url获得图片asset失败！");
                }];
            }
            
            // TODO 如果要使用第三方相片选择器选择视频文件，可能需要修改if判断逻辑
            //    // Handle a movie capture
            //    if (CFStringCompare ((CFStringRef) mediaType, kUTTypeMovie, 0)
            //        == kCFCompareEqualTo) {
            //
            //        NSString *moviePath = [[info objectForKey:
            //                                UIImagePickerControllerMediaURL] path];
            //
            //        if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)) {
            //            UISaveVideoAtPathToSavedPhotosAlbum (
            //                                                 moviePath, nil, nil, nil);
            //        }
            //    }
        }
        
        // 注：系统不会自动关闭，需要手动关闭
        [picker dismissViewControllerAnimated:YES completion:nil];
    };
    
    
    [self.view addSubview:upd];
}

- (void) testFile {
//    // == 一：获取沙盒目录
//    //
//    // 获取程序的根目录（home）目录
//    NSString *homePath = NSHomeDirectory();
//    NSLog(@"homePath:%@", homePath);
//    // 获取Document目录
//    NSArray  *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//    NSString *docPath = [paths lastObject];
//    NSLog(@"docPath:%@", docPath);
//    // 获取Library目录
//    paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
//    NSString *libraryPath = [paths lastObject];
//    NSLog(@"libraryPath:%@", libraryPath);
//    // 获取Library中的Cache
//    paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
//    NSString *cachePath = [paths lastObject];
//    NSLog(@"cachePath:%@", cachePath);
//    // 获取temp路径
//    NSString *tempPath = NSTemporaryDirectory();
//    NSLog(@"tempPath:%@", tempPath);
//    
//    
//    // 二：NSString类路径的处理方法
//    //
//    // homePath:/var/mobile/Containers/Data/Application/2A7615BD-AF70-4B07-99D8-4F0BA47CA3CA
//    //
//    // 获得组成此路径的各个组成部分，结果：（/ | var | mobile | Containers | Data | Application | 2A7615BD-AF70-4B07-99D8-4F0BA47CA3CA）
//    NSArray * pathComponents = [homePath pathComponents];
//    NSLog(@"pathComponents:%@", [TSCMyUtil implodeWithGlue:@" | " array:pathComponents]);
//    // 提取路径的最后一个组成部分，结果：2A7615BD-AF70-4B07-99D8-4F0BA47CA3CA
//    NSLog(@"lastPathComponent:%@", [homePath lastPathComponent]);
//    // 删除路径的最后一个组成部分，结果：/var/mobile/Containers/Data/Application
//    NSLog(@"stringByDeletingLastPathComponent:%@", [homePath stringByDeletingLastPathComponent]);
//    // 将path添加到先邮路径的末尾，结果：/var/mobile/Containers/Data/Application/2A7615BD-AF70-4B07-99D8-4F0BA47CA3CA/.last
//    NSLog(@"stringByAppendingPathComponent:%@", [homePath stringByAppendingPathComponent:@".last"]); // 注：有“点”
//    // 取路径最后部分的扩展名，结果：
//    NSLog(@"pathExtension:%@", [homePath pathExtension]);
//    // 删除路径最后部分的扩展名，结果：/var/mobile/Containers/Data/Application/2A7615BD-AF70-4B07-99D8-4F0BA47CA3CA
//    NSLog(@"stringByDeletingPathExtension:%@", [homePath stringByDeletingPathExtension]);
//    // 路径最后部分追加扩展名，结果：/var/mobile/Containers/Data/Application/2A7615BD-AF70-4B07-99D8-4F0BA47CA3CA.last
//    NSLog(@"stringByAppendingPathExtension:%@", [homePath stringByAppendingPathExtension:@"last"]); // 注：没有“点”
    
//    // 三：创建文件
////    [TSCMyUtil makeFile:FileTypeImgTemp fileName:@"temp1.jpg" overwrite:NO];
//    NSString * filePath = [TSCMyUtil makeFile:FileTypeImgTemp fileName:nil overwrite:NO];
//    NSLog(@"Done! FilePath: %@", filePath);
    
//    // 四：转换函数
//    NSString * fileUrl1 = @"http://ww4.sinaimg.cn/crop.61.0.339.339.1024/66776e6d";
//    NSString * fileUrl2 = @"http://tscpubsys.qiniudn.com/shop_pic.jpeg";
//    NSLog(@"1: %@", [TSCMyUtil fileUrl2FileName:FileTypeImgPic fileUrl:fileUrl1 thumbnailType:ThumbnailType0]);
//    NSLog(@"2: %@", [TSCMyUtil fileUrl2FileName:FileTypeImgPic fileUrl:fileUrl2 thumbnailType:ThumbnailType1]);
//    NSLog(@"3: %@", [TSCMyUtil fileUrl2FilePath:FileTypeImgPic fileUrl:fileUrl1 thumbnailType:ThumbnailType0]);
//    NSLog(@"4: %@", [TSCMyUtil fileUrl2FilePath:FileTypeImgFace fileUrl:fileUrl2 thumbnailType:ThumbnailType1]);
    
//    // 五：copy文件
//    NSString * fileUrl1 = @"http://ww4.sinaimg.cn/crop.61.0.339.339.1024/66776e6d";
//    NSString * originalFilePath = [TSCMyUtil makeFile:FileTypeImgPic fileName:nil overwrite:YES];
//    NSString * copiedFilePath = [TSCMyUtil copyFile:FileTypeImgPic oldPath:originalFilePath overwrite:YES picUrl:fileUrl1];
//    NSLog(@"originalFilePath: %@", originalFilePath);
//    NSLog(@"copiedFilePath: %@", copiedFilePath);
    
    // 六：创建缩略图（注：在 testUploadPicDialog() 中测试）
}


- (void) testPhotoEditor {

}

- (void) testHTTPGet {
    [TSCMyHttpUtil getWithUrl:URL_GET_PIC_SERVER_TOKEN completionHandler:^(ServerRespType serverRespType, NSString *resp) {
        // 服务器返回错误处理
        switch (serverRespType) {
            case ServerRespTypeSuccess:
                break;
            case ServerRespTypeErrNil:
            default:
                dispatch_async(dispatch_get_main_queue(), ^{
                    [TSCMyUIUtil popErrWithResourceKey:@"err_system"];
                });
                return;
        }
       
        NSLog(@"服务器返回：%@", resp);

        
    }];
}

- (void) testUploadImageUtil {
 
    
        NSURL * url = [NSURL URLWithString:@"assets-library://asset/asset.JPG?id=F9007CC9-05DC-4916-B723-1DECC562119C&ext=JPG"]; // 大：横
//    NSURL * url = [NSURL URLWithString:@"assets-library://asset/asset.JPG?id=7A88D41A-2E22-40C6-B150-49EAED51E613&ext=JPG"]; // 大：竖
//        NSURL * url = [NSURL URLWithString:@"assets-library://asset/asset.JPG?id=93DC1E12-C389-479F-9993-2F4B43F97E0A&ext=JPG"]; // 小：横
//        NSURL * url = [NSURL URLWithString:@"assets-library://asset/asset.JPG?id=4CFC0C6D-4239-47D6-98C2-0C307373881A&ext=JPG"]; // 小：竖

    ALAssetsLibrary * library = [[ALAssetsLibrary alloc]init];
    [library assetForURL:url resultBlock:^(ALAsset *asset) {
        ALAssetRepresentation *representation = [asset defaultRepresentation];

        CGFloat scale = representation.scale;
        UIImageOrientation orientation = (UIImageOrientation)representation.orientation; // 默认1.0f
        CGImageRef imgRef = representation.fullResolutionImage; // 默认0
        UIImage * imageFromAsset = [[UIImage alloc]initWithCGImage:imgRef scale:scale orientation:orientation];

       // 上传图片到图片服务器
        
        NSMutableDictionary * picKeyImageDic = [NSMutableDictionary dictionary];
        [picKeyImageDic setObject:imageFromAsset forKey:@"logo"];
        
        TSCMyUploadImageUtil * uploadImageUtil = [[TSCMyUploadImageUtil alloc]init];
        uploadImageUtil.picKeyImageDic = picKeyImageDic;
        uploadImageUtil.onProgress = ^(NSString * picName, float percent) {
            NSLog(@"onProgress():[key:%@, percent:%f]", picName, percent);
        };
        uploadImageUtil.onSuccessOne = ^(NSString * key, NSString * imgUrl) {
            NSLog(@"onSuccessOne():[key:%@, imgUrl:%@]", key, imgUrl);
        };
        uploadImageUtil.onSuccessAll = ^(NSMutableDictionary * picKeyUrlDic) {
            NSLog(@"onSuccessAll():[dic:%@]", picKeyUrlDic);
        };
        uploadImageUtil.onFailure = ^(NSError * error) {
            NSLog(@"onFailure():[error:%@]", error);
            
        };
        [uploadImageUtil startUpload_P1];
        
    } failureBlock:^(NSError *error) {
        NSLog(@"通过url获得图片asset失败！");
    }];
}

- (void) testPopMenu {
    
    TSCMyPopupMenu * popMenu = [[TSCMyPopupMenu alloc]init];
    popMenu.rowIconArray = [NSArray arrayWithObjects:@"ic_user_96x96.png", @"ic_help_96x96.png", @"ic_letter_96x96.png", @"ic_shop_96x96.png", nil];
    popMenu.rowTextArray = [NSArray arrayWithObjects:
//                            @"第一行", @"第二行",
                            @"",@"",
                            @"第三行", @"第四行",
                            nil];
    popMenu.rowOnClickListenerArray = [NSArray arrayWithObjects:
                                       ^(NSIndexPath * indexPath) {
                                           NSLog(@"点击了第一项...");
                                       },
                                       ^(NSIndexPath * indexPath) {
                                           NSLog(@"点击了第二项...");
                                       },
                                       ^(NSIndexPath * indexPath) {
                                           NSLog(@"点击了第三项...");
                                       },
                                       ^(NSIndexPath * indexPath) {
                                           NSLog(@"点击了第四项...");
                                       },
                                       nil];
    
    TSCMyClickBtn * btn = [TSCMyClickBtn buttonWithType:UIButtonTypeSystem];
    btn.frame = CGRectMake(50, 50, 200, 200);
    btn.backgroundColor = COLOR_MT;
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn setTitle:@"测试按钮" forState:UIControlStateNormal];
    btn.btnClickedListener = ^(TSCMyClickBtn *button) {
        [popMenu show];
    };
    [self.view addSubview:btn];
    
}

- (void) testTimestamp {
    NSLog(@"1: %li", [TSCMyUtil getTsFromDateStr:@"20150921-203001" format:@"yyyyMMdd-HHmmss"]);
    
//    NSTimeInterval * ti;
    NSInteger tsNow = [NSDate date].timeIntervalSince1970;
    NSInteger tsTomorrow = [TSCMyUtil getTsTomorrow:tsNow];
    NSLog(@"2: %li", tsNow);
    NSLog(@"3: %li", tsTomorrow);
}

- (void) testDBUtilMsg {
    
//    NSInteger userId = [[_ud objectForKey:AEKI_USER_ID] integerValue];
    NSInteger userId = 5; // 导购小瑾
    
    TSCLinearLayout * ll = [[TSCLinearLayout alloc]init];
    ll.frame = CGRectMake(50, 50, 500, 500);
    ll.distribution = LINEAR_LAYOUT_DISTRIBUTION_FILL_EQUALLY;
    [self.view addSubview:ll];
    
    TSCMyClickBtn * btn1 = [TSCMyClickBtn buttonWithType:UIButtonTypeSystem];
    [btn1 setTitle:@"1 getUnreadMsgNumWithUserId_1" forState:UIControlStateNormal];
    [ll addSubview:btn1];
    btn1.btnClickedListener = ^(TSCMyClickBtn * btn) {
        NSLog(@"getUnreadMsgNumWithUserId_1:%li", [TSCMyDBUtil getUnreadMsgNumWithUserId_1:userId types:@"" isReaded:DB_ANY]);
    };
   
    TSCMyClickBtn * btn2 = [TSCMyClickBtn buttonWithType:UIButtonTypeSystem];
    [btn2 setTitle:@"2 getUnreadMsgWithUserId_1" forState:UIControlStateNormal];
    [ll addSubview:btn2];
    btn2.btnClickedListener = ^(TSCMyClickBtn * btn) {
        NSLog(@"getUnreadMsgWithUserId_1:%@", [TSCMyDBUtil getUnreadMsgWithUserId_1:userId type:1 msgId:1]);
    };
    
    TSCMyClickBtn * btn3 = [TSCMyClickBtn buttonWithType:UIButtonTypeSystem];
    [btn3 setTitle:@"3 getUnreadMsgListWithUserId_1" forState:UIControlStateNormal];
    [ll addSubview:btn3];
    btn3.btnClickedListener = ^(TSCMyClickBtn * btn) {
        NSArray * arr = [TSCMyDBUtil getUnreadMsgListWithUserId_1:userId types:@"" lastMsgId:0 senderName:@"" createDateStr:@"" isReaded:DB_ANY isFavorite:DB_ANY];
        NSLog(@"getUnreadMsgListWithUserId_1:%@", arr);
    };
    
    TSCMyClickBtn * btn4 = [TSCMyClickBtn buttonWithType:UIButtonTypeSystem];
    [btn4 setTitle:@"4 insertUnreadMsgWithUserId_1" forState:UIControlStateNormal];
    [ll addSubview:btn4];
    btn4.btnClickedListener = ^(TSCMyClickBtn * btn) {
        [TSCMyDBUtil insertUnreadMsgWithUserId_1:userId msgType:1 msgId:1 si:2 sn:@"rio" spu:@"http://" info:@"info" ct:1 isReaded:DB_NO isFavorited:DB_NO];
        NSLog(@"insertUnreadMsgWithUserId_1, done");
    };
    
    TSCMyClickBtn * btn5 = [TSCMyClickBtn buttonWithType:UIButtonTypeSystem];
    [btn5 setTitle:@"5 deleteAllUnreadMsgWithUserId_1" forState:UIControlStateNormal];
    [ll addSubview:btn5];
    btn5.btnClickedListener = ^(TSCMyClickBtn * btn) {
        [TSCMyDBUtil deleteAllUnreadMsgWithUserId_1:userId];
        NSLog(@"deleteAllUnreadMsgWithUserId_1, done");
    };
    
    TSCMyClickBtn * btn6 = [TSCMyClickBtn buttonWithType:UIButtonTypeSystem];
    [btn6 setTitle:@"6 deleteUnreadMsgWithMsgId_1" forState:UIControlStateNormal];
    [ll addSubview:btn6];
    btn6.btnClickedListener = ^(TSCMyClickBtn * btn) {
        [TSCMyDBUtil deleteUnreadMsgWithMsgId_1:1];
        NSLog(@"deleteUnreadMsgWithMsgId_1, done");
    };
    
    TSCMyClickBtn * btn7 = [TSCMyClickBtn buttonWithType:UIButtonTypeSystem];
    [btn7 setTitle:@"7 markUnreadMsgReadedWithMsgId_1" forState:UIControlStateNormal];
    [ll addSubview:btn7];
    btn7.btnClickedListener = ^(TSCMyClickBtn * btn) {
        [TSCMyDBUtil markUnreadMsgReadedWithMsgId_1:1];
        NSLog(@"markUnreadMsgReadedWithMsgId_1, done");
    };
    
    TSCMyClickBtn * btn8 = [TSCMyClickBtn buttonWithType:UIButtonTypeSystem];
    [btn8 setTitle:@"8 markUnreadMsgFavoritedWithMsgId_1" forState:UIControlStateNormal];
    [ll addSubview:btn8];
    btn8.btnClickedListener = ^(TSCMyClickBtn * btn) {
        [TSCMyDBUtil markUnreadMsgFavoritedWithMsgId_1:1 isFavorited:DB_YES];
        NSLog(@"markUnreadMsgFavoritedWithMsgId_1, done");
    };
  
    
}

- (void) testSidebar {
    // 创建搜索栏
    TSCMySidebar * sidebar = [[TSCMySidebar alloc]init];
    sidebar.vcMain = self;
//        sidebar.presentStyle = TSCSidebarPresentStyleFlyFromTop;
//        sidebar.presentStyle = TSCSidebarPresentStyleFlyFromLeft;
        sidebar.presentStyle = TSCSidebarPresentStyleFlyFromBottom;
//    sidebar.presentStyle = TSCSidebarPresentStyleFlyFromRight;
    sidebar.hasBGColor = NO;
    sidebar.hasRoundCorner = NO;
    sidebar.hasShadow = YES;
    sidebar.bgClickedDismissAnimated = YES;
    sidebar.bgClickedDismissCompletion = ^() {
        NSLog(@"BG:已关闭！");
    };
//    sidebar.dialogWType = TSCSidebarDialogWHTypeFillParent;
//    sidebar.dialogHType = TSCSidebarDialogWHTypeFillParent;
//    sidebar.dialogWType = TSCSidebarDialogWHTypeFix;
//    sidebar.dialogW = 50;
//    sidebar.dialogHType = TSCSidebarDialogWHTypeFix;
//    sidebar.dialogH = 100;
    
    
    // 创建customView（1）GCSelecor
    // 可以正常显示
    TSCMyGCSelector * gcSelector = [[TSCMyGCSelector alloc]init];
    gcSelector.maxRows = 3;
    gcSelector.availableGCIds = @"";
    gcSelector.selectedGCIds = @"";
    [gcSelector drawUI];
    [gcSelector setupViewData_1];
    
    sidebar.dialogWType = TSCSidebarDialogWHTypePrefer;
    sidebar.dialogHType = TSCSidebarDialogWHTypeDynamic;
    sidebar.dialogCustomViewSizePosition = TSCSideBarDialogCustomViewSizePositionFillParent;
    NSLog(@"height00:%f", gcSelector.frame.size.height);
    sidebar.customView = gcSelector;
    
    
//     // 创建customView（2）从xib中加载
//     // 可以正常显示
//     UIView * xibView = [[NSBundle mainBundle]loadNibNamed:@"TestDialog" owner:nil options:nil][0];
//    //    sidebar.dialogWType = TSCSidebarDialogWHTypeFix;
////    sidebar.dialogHType = TSCSidebarDialogWHTypeFix;
////    sidebar.dialogW = 500;
////    sidebar.dialogH = 300;
////    sidebar.dialogWType = TSCSidebarDialogWHTypeFillParent;
////    sidebar.dialogHType = TSCSidebarDialogWHTypeFillParent;
//    sidebar.dialogWType = TSCSidebarDialogWHTypePrefer;
//    sidebar.dialogHType = TSCSidebarDialogWHTypePrefer;
////    sidebar.dialogWType = TSCSidebarDialogWHTypeDynamic;
////    sidebar.dialogHType = TSCSidebarDialogWHTypeDynamic;
////    sidebar.dialogCustomViewSizePosition = TSCSideBarDialogCustomViewSizePositionUseFrame;
//    sidebar.dialogCustomViewSizePosition = TSCSideBarDialogCustomViewSizePositionFillParent;
//    sidebar.customView = xibView;
    
    
//    // 创建customView（3）MyDatePicker
//    // 可以正常显示
//    TSCMyDatePicker * mdp = [TSCMyDatePicker loadFromXib];
//    mdp.btnClickedListenerConfirm = ^(UIButton * btn) {
//        NSLog(@"点击了[确定]按钮");
//    };
//    mdp.btnClickedListenerCancel = ^(UIButton * btn) {
//        NSLog(@"点击了[取消]按钮");
//    };
//    mdp.btnClickedListenerNoSelect = ^(UIButton * btn) {
//        NSLog(@"点击了[不选]按钮");
//    };
//    mdp.datePickerMode = UIDatePickerModeDate;
//    mdp.initialDate = [NSDate date];
//    mdp.minimumDate = [NSDate dateWithTimeIntervalSinceNow: - 3600 * 24];
//    mdp.maximumDate = [NSDate dateWithTimeIntervalSinceNow: 3600 * 24];
//    sidebar.dialogWType = TSCSidebarDialogWHTypeDynamic;
//    sidebar.dialogHType = TSCSidebarDialogWHTypeDynamic;
//    sidebar.dialogCustomViewSizePosition = TSCSideBarDialogCustomViewSizePositionFillParent;
//    sidebar.customView = mdp;

    
//    // 创建customView（4）UIDatePicker
//    // 可以正常显示
//    UIDatePicker * dp = [[UIDatePicker alloc]init];
//    dp.datePickerMode = UIDatePickerModeDate;
//    dp.minimumDate = [NSDate dateWithTimeIntervalSinceNow: - 3600 * 24];
//    dp.maximumDate = [NSDate dateWithTimeIntervalSinceNow: 3600 * 24];
//    sidebar.dialogWType = TSCSidebarDialogWHTypeDynamic;
//    sidebar.dialogHType = TSCSidebarDialogWHTypeDynamic;
//    sidebar.dialogCustomViewSizePosition = TSCSideBarDialogCustomViewSizePositionFillParent;
//    sidebar.customView = dp;
    
    
//    // 创建customView（5）任意一个UIView
//    // 可以正常显示
//    UIView * sv1 = [[UIView alloc]init];
//    sv1.frame = CGRectMake(0, 0, 100, 50);
//    sv1.backgroundColor = [UIColor yellowColor];
//    sidebar.dialogWType = TSCSidebarDialogWHTypeDynamic;
//    sidebar.dialogHType = TSCSidebarDialogWHTypeDynamic;
//    sidebar.dialogCustomViewSizePosition = TSCSideBarDialogCustomViewSizePositionFillParent;
//    sidebar.customView = sv1;
    
    
    TSCMyClickBtn * btn = [[TSCMyClickBtn alloc]init];
    btn.frame = CGRectMake(100, 100, 50, 50);
    btn.backgroundColor = [UIColor redColor];
    [btn setTitle:@"出现" forState:UIControlStateNormal];
    btn.btnClickedListener = ^(TSCMyClickBtn * btn) {
        [sidebar presentAnimated:YES completion:^(){
            NSLog(@"已出现");
        }];
    };
    [self.view addSubview:btn];
    
    //    TSCMyClickBtn * btn2 = [[TSCMyClickBtn alloc]init];
    //    btn2.frame = CGRectMake(150, 100, 50, 50);
    //    btn2.backgroundColor = [UIColor yellowColor];
    //    [btn2 setTitle:@"消失" forState:UIControlStateNormal];
    //    btn2.btnClickedListener = ^(TSCMyClickBtn * btn) {
    //        [sidebar dismissAnimated:YES completion:
    //         ^(){
    //            NSLog(@"已消失");
    //        }
    //         ];
    //    };
    //    [self.view addSubview:btn2];
}

- (void) testLoadXibFullScreen {
    UIView * xibView = [[NSBundle mainBundle]loadNibNamed:@"TestDialog" owner:nil options:nil][0];
    [self.view addSubview:xibView];
    
    [TSCMyUIUtil addConstraintsFillParent2View:xibView isActiveImmediately:YES];
//    xibView.translatesAutoresizingMaskIntoConstraints = NO;
//    [NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[xibView]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(xibView)]];
//    [NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[xibView]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(xibView)]];
}

- (void) testAddConstraintUpdateFrame {
    UIView * v1 = [[UIView alloc]init];
    v1.backgroundColor = [UIColor redColor];
    [self.view addSubview:v1];
    NSLog(@"frame1: %@", NSStringFromCGRect(v1.frame));
    
    v1.frame = CGRectMake(50, 50, 100, 100);
    NSLog(@"frame2: %@", NSStringFromCGRect(v1.frame));
    
    v1.translatesAutoresizingMaskIntoConstraints = NO;
    NSLog(@"frame3: %@", NSStringFromCGRect(v1.frame));
    
    NSMutableArray * ctArr = [[NSMutableArray alloc]init];
    [ctArr addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[v1]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(v1)]];
    [ctArr addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[v1]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(v1)]];
    NSLog(@"frame4: %@", NSStringFromCGRect(v1.frame));
    
    // OK
    dispatch_async(dispatch_get_main_queue(), ^{
        NSLog(@"frame5: %@", NSStringFromCGRect(v1.frame));
    });

    // NO
    [NSLayoutConstraint activateConstraints:ctArr];
//    [v1 layoutIfNeeded]; // 关键在于这一句啊！加上这一句，就可以在设置完constraints之后，立即获得view的新宽度、高度了。参考：http://stackoverflow.com/questions/13446920/how-can-i-get-a-views-current-width-and-height-when-using-autolayout-constraint
    NSLog(@"frame6: %@", NSStringFromCGRect(v1.frame));
    
//    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//        [NSThread sleepForTimeInterval:0.001];
    
    // OK
        dispatch_async(dispatch_get_main_queue(), ^{
             NSLog(@"frame7: %@", NSStringFromCGRect(v1.frame));
        });
//    });
    
}

- (void) testAddConstraintUpdateFrame2 {
    UIView * v1 = [[UIView alloc]init];
    v1.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:v1];
    
    UIButton * btn = [UIButton buttonWithType:UIButtonTypeSystem];
    btn.backgroundColor = [UIColor redColor];
    [btn setTitle:@"按钮" forState:UIControlStateNormal];
    btn.frame = CGRectMake(0, 0, 100, 50);
    [v1 addSubview:btn];
    
//    btn.translatesAutoresizingMaskIntoConstraints = NO;
//    [NSLayoutConstraint constraintWithItem:btn attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0f constant:100.0f].active = YES;
//    [NSLayoutConstraint constraintWithItem:btn attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0f constant:50.0f].active = YES;
    
    
//    // 方法一：子view填充父view（父view已确定size）
//    [TSCMyUIUtil addConstraintsFillParent2View:btn isActiveImmediately:YES];
    
//    // 方法二：父view贴合子view-等高、等宽（子view已确定size）
//    v1.translatesAutoresizingMaskIntoConstraints = NO;
//    [NSLayoutConstraint constraintWithItem:v1 attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:btn attribute:NSLayoutAttributeWidth multiplier:1.0f constant:0.0f].active = YES;
//    [NSLayoutConstraint constraintWithItem:v1 attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:btn attribute:NSLayoutAttributeHeight multiplier:1.0f constant:0.0f].active = YES;
    
    // 方法三：父view贴合子view-top、left、bottom、right（子view已确定size）
    v1.translatesAutoresizingMaskIntoConstraints = NO;
    [NSLayoutConstraint constraintWithItem:v1 attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:btn attribute:NSLayoutAttributeTop multiplier:1.0f constant:0.0f].active = YES;
    [NSLayoutConstraint constraintWithItem:v1 attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:btn attribute:NSLayoutAttributeLeft multiplier:1.0f constant:0.0f].active = YES;
    [NSLayoutConstraint constraintWithItem:v1 attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:btn attribute:NSLayoutAttributeBottom multiplier:1.0f constant:0.0f].active = YES;
    [NSLayoutConstraint constraintWithItem:v1 attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:btn attribute:NSLayoutAttributeRight multiplier:1.0f constant:0.0f].active = YES;
    

    
    [v1 layoutIfNeeded];
    [btn layoutIfNeeded];
    NSLog(@"size 1: %@", NSStringFromCGRect(btn.frame));
    NSLog(@"size 2: %@", NSStringFromCGRect(v1.frame));
}

- (void) testDatepicker {
    UIDatePicker * dp = [[UIDatePicker alloc]init];
//    dp.backgroundColor = [UIColor yellowColor];
    dp.minimumDate = [NSDate date]; // 当前日期
    dp.maximumDate = [NSDate dateWithTimeIntervalSinceNow:3600*24]; // 明天
    dp.datePickerMode = UIDatePickerModeDateAndTime;
//    dp.timeZone = [NSTimeZone systemTimeZone];
    dp.timeZone = [NSTimeZone localTimeZone];
    NSLog(@"frame 1:%@", NSStringFromCGRect(dp.frame)); // datePicker的宽度、高度，在此时就已经确定。标准尺寸为：[320, 216]
    [self.view addSubview:dp];
//    NSLog(@"frame 2:%@", NSStringFromCGRect(dp.frame));
//    dp.frame = CGRectMake(0, 0, 500, 500);
//    NSLog(@"frame 3:%@", NSStringFromCGRect(dp.frame));
//    dp.frame = CGRectMake(0, 0, 200, 100);
//    NSLog(@"frame 4:%@", NSStringFromCGRect(dp.frame));
    NSLog(@"timeZone:%@", dp.timeZone);
    NSLog(@"countDownDuration:%f", dp.countDownDuration);
    
    TSCMyClickBtn * btn = [TSCMyClickBtn buttonWithType:UIButtonTypeSystem];
    btn.frame = CGRectMake(200, 200, 100, 50);
    btn.backgroundColor = [UIColor yellowColor];
    [btn setTitle:@"看日期（时间）" forState:UIControlStateNormal];
    btn.btnClickedListener = ^(TSCMyClickBtn * btn) {
        NSLog(@"日期（时间）：%@", dp.date);
        NSLog(@"countDownDuration:%f", dp.countDownDuration);
    };
    [self.view addSubview:btn];
    
    return;
    
    // 规则说明：
    // 1. UIDatePicker初始后（init()之后，添加到父view前），不用手工指定frame，自动具有默认的frame（标准尺寸）：{{0, 0}, {320, 216}}。
    // 2. frame可以设置。如果设置尺寸超过标准尺寸，则多余区域颜色保持背景色一致；如果设置尺寸小于标准尺寸，则UIDatePicker中显示不下的内容用省略号代替。
    // 3. UIDatePicker可以在StoryBoard中直接拖拽产生，这样就可以在xib中拖拽产生UIDatePicker，并和其他UI控件联合使用，设置约束，进行复用。
    
//    UIView * xibView = [[NSBundle mainBundle]loadNibNamed:@"TSCMyDatePicker" owner:nil options:nil][0];
//    NSLog(@"frame 1:%@", NSStringFromCGRect(xibView.frame));
//    xibView.frame = CGRectMake(0, 0, 320, 400);
//    NSLog(@"frame 2:%@", NSStringFromCGRect(xibView.frame));
//    [self.view addSubview:xibView];
    
    TSCMyDatePicker * mdp = [TSCMyDatePicker loadFromXib];
    mdp.btnClickedListenerConfirm = ^(UIButton * btn, NSDate * date) {
        NSLog(@"点击了[确定]按钮");
    };
    mdp.btnClickedListenerCancel = ^(UIButton * btn, NSDate * date) {
        NSLog(@"点击了[取消]按钮");
    };
    mdp.btnClickedListenerNoSelect = ^(UIButton * btn, NSDate * date) {
        NSLog(@"点击了[不选]按钮");
    };
    mdp.datePickerMode = UIDatePickerModeDate;
    mdp.initialDate = [NSDate date];
    mdp.minimumDate = [NSDate dateWithTimeIntervalSinceNow: - 3600 * 24];
    mdp.maximumDate = [NSDate dateWithTimeIntervalSinceNow: 3600 * 24];
    [self.view addSubview:mdp];
//    NSLog(@"frame 1:%@", NSStringFromCGRect(mdp.frame));
//    mdp.frame = CGRectMake(0, 0, 500, 500);
//    NSLog(@"frame 2:%@", NSStringFromCGRect(mdp.frame));
//    mdp.frame = CGRectMake(0, 0, 200, 200);
//    NSLog(@"frame 3:%@", NSStringFromCGRect(mdp.frame));
    
}

- (void) testMyCellCommon {
    // 注：测试时需要通过UITableView，我是在TSCVCGuideBizListPage.m中直接测试的，而不是在TSCVCTest.m中
    // 这里仅保留部分测试代码，当需要测试时，请将测试代码移入UITableView的delegate方法：
    // - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
//    static NSString *cellReuseId = @"textCell";
//    TSCMyCellCommon *cell = [tableView dequeueReusableCellWithIdentifier:cellReuseId];
//    if (cell == nil) {
//        cell = [[TSCMyCellCommon alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellReuseId];
//        //        cell.backgroundColor = COLOR_MT_SPINNER_CELL_BG;
//    }
//    
//    cell.ivPic.image = [UIImage imageNamed:@"ic_app_logo_96x96.png"];
//    
//    cell.lb1.text = @"lb1";
//    cell.lb2.text = @"lb2";
//    
//    cell.lbTime.text = @"2015年10月08日";
//    //    cell.lbTime.hidden = YES;
//    
//    //    cell.lbRb.hidden = NO;
//    //    cell.lbRb.text = @"lbRb";
//    //    cell.ivRb.hidden = NO;
//    //    cell.ivRb.image = [UIImage imageNamed:@"ic_app_logo_96x96.png"];
//    
//    //    cell.ivRbGp1.hidden = NO;
//    //    cell.ivRbGp2.hidden = NO;
//    //    cell.ivRbGp3.hidden = NO;
//    //    cell.ivRbGp1.image = [UIImage imageNamed:@"ic_help_96x96.png"];
//    //    cell.ivRbGp2.image = [UIImage imageNamed:@"ic_lock_96x96.png"];
//    //    cell.ivRbGp3.image = [UIImage imageNamed:@"ic_app_logo_96x96.png"];

    
    //}
    
    
}

// 因为IOS需要交费成为开发者才能开通消息服务，所以暂时通过手工方式插入APP_DB（模拟消息服务推送来的消息）进行测试
- (void) testInsetAppDB {
    
    [TSCMyDBHelper deleteWithTableName:DB_TABLE_NAME_MSG whereDictionary:nil];
    
    [TSCMyDBHelper insertWithTableName:DB_TABLE_NAME_MSG keyValueDictionary:
     [NSDictionary dictionaryWithObjectsAndKeys:
      //
      @"5", // 导购小瑾
      @"user_id",
      //
      @"11",
      @"msg_id",
      //
      [NSNumber numberWithInteger:DB_MSG_TYPE_CUSTOMER_WANT_BUY],
      @"type",
      //
      @"1",
      @"sender_id",
      //
      @"小洁",
      @"sender_name",
      //
      @"http://tscpub.qiniudn.com/Fqh7kRVa01bvUoVubOtbsy5KIS7m",
      @"sender_pic_url",
      //
      @"我想买一双黑色船鞋",
      @"info",
      //
      [NSNumber numberWithInteger:1444292957], // 2015-10-08 16:29:XX
      @"create_time",
      //
      @"0",
      @"is_readed",
      //
      @"0",
      @"is_favorited",
      nil]
     ];
    
    
    [TSCMyDBHelper insertWithTableName:DB_TABLE_NAME_MSG keyValueDictionary:
     [NSDictionary dictionaryWithObjectsAndKeys:
      //
      @"5", // 导购小瑾
      @"user_id",
      //
      @"12",
      @"msg_id",
      //
      [NSNumber numberWithInteger:DB_MSG_TYPE_CUSTOMER_Q_IN_FIRST_REPLY],
      @"type",
      //
      @"2",
      @"sender_id",
      //
      @"顾2",
      @"sender_name",
      //
      @"http://tscpub.qiniudn.com/FnPsMaDGZPElHFlzSOkLJHFex4pi",
      @"sender_pic_url",
      //
      @"你的这条打底裤，最低多少钱？",
      @"info",
      //
      [NSNumber numberWithInteger:1444292957 - 3600 * 24],
      @"create_time",
      //
      @"0",
      @"is_readed",
      //
      @"0",
      @"is_favorited",
      nil]
     ];
    
    [TSCMyDBHelper insertWithTableName:DB_TABLE_NAME_MSG keyValueDictionary:
     [NSDictionary dictionaryWithObjectsAndKeys:
      //
      @"5", // 导购小瑾
      @"user_id",
      //
      @"13",
      @"msg_id",
      //
      [NSNumber numberWithInteger:DB_MSG_TYPE_CUSTOMER_Q_IN_LIMIT_SELL],
      @"type",
      //
      @"3",
      @"sender_id",
      //
      @"顾3",
      @"sender_name",
      //
      @"http://tscpub.qiniudn.com/FnjSMDHGPjKFFsdwRM1Vvfo7xqFK",
      @"sender_pic_url",
      //
      @"这条连衣裙限时到什么时候？",
      @"info",
      //
      [NSNumber numberWithInteger:1444292957 - 3600 * 24 * 2],
      @"create_time",
      //
      @"0",
      @"is_readed",
      //
      @"0",
      @"is_favorited",
      nil]
     ];
    
    for (NSInteger i = 1; i <= 50; i++) {
        [TSCMyDBHelper insertWithTableName:DB_TABLE_NAME_MSG keyValueDictionary:
         [NSDictionary dictionaryWithObjectsAndKeys:
          //
          @"5", // 导购小瑾
          @"user_id",
          //
          [NSNumber numberWithInteger:13 + i],
          @"msg_id",
          //
          [NSNumber numberWithInteger:DB_MSG_TYPE_CUSTOMER_WANT_BUY],
          @"type",
          //
          @"3",
          @"sender_id",
          //
          @"顾3",
          @"sender_name",
          //
          @"http://tscpub.qiniudn.com/FnjSMDHGPjKFFsdwRM1Vvfo7xqFK",
          @"sender_pic_url",
          //
          [NSString stringWithFormat:@"我想买一条很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长的连衣裙%li", i],
          @"info",
          //
          [NSNumber numberWithInteger:1444292957 - 3600 * 24 * 2 + 60 * i],
          @"create_time",
          //
          @"0",
          @"is_readed",
          //
          @"0",
          @"is_favorited",
          nil]
         ];
    }
    
    NSArray * resultArr = [TSCMyDBHelper selectWithSql:[NSString stringWithFormat:@"SELECT * FROM %@", DB_TABLE_NAME_MSG]];
    NSLog(@"Done...Inserted rows:");
    int row = 1;
    for (NSDictionary * dic in resultArr) {
        NSMutableString * rowStr = [NSMutableString string];
        for (NSString * key in [dic allKeys]) {
            [rowStr appendFormat:@"%@:%@, ", key, [dic objectForKey:key]];
        }
        NSLog(@"%i: %@", row, rowStr);
        row++;
    }
    
    
}

- (void) testTextView {
    UITextField * tf = [[UITextField alloc] init];
//    tf.backgroundColor = [UIColor yellowColor];
    [TSCMyUIUtil setUIRoundBorder:tf radius:5.0f borderColor:COLOR_MT_BORDER_LIGHT_GRAY borderWidth:1.0f];
    tf.frame = CGRectMake(50, 50, 300, 50);
    tf.placeholder = @"这是";
    [self.view addSubview:tf];
    
//    self.automaticallyAdjustsScrollViewInsets = NO; // 取消scrollView上方的空白
//    
//    UITextView  * tv = [[UITextView alloc] init];
////    tv.backgroundColor = [UIColor lightGrayColor];
//    [TSCMyUIUtil setUIRoundBorder:tv radius:5.0f borderColor:COLOR_MT_BORDER_LIGHT_GRAY borderWidth:1.0f];
//    tv.frame = CGRectMake(50, 150, 300, 100);
//    [self.view addSubview:tv];
    
    TSCMyTextView * tv = [[TSCMyTextView alloc]init];
    tv.frame = CGRectMake(50, 150, 300, 100);
    [self.view addSubview:tv];
    tv.placeholder = @"请在这里输入内容...";
    tv.font = [TSCMyUIUtil getSystemDefaultFont];
//    tv.text = @"这是一段话";
    
    TSCMyClickBtn * btn = [TSCMyClickBtn buttonWithType:UIButtonTypeSystem];
    btn.frame = CGRectMake(50, 300, 300, 50);
    btn.backgroundColor = [UIColor lightGrayColor];
    [btn setTitle:@"给MyTextView设置内容" forState:UIControlStateNormal];
    btn.btnClickedListener = ^(TSCMyClickBtn * btn) {
        tv.text = @"通过btn设置内容";
    };
    [self.view addSubview:btn];
}

- (void) testRadioButton {
    NSMutableArray <NikiRadioButton *> * rbg = [NSMutableArray array];
    
//    NikiRadioButton * rb1 = [NikiRadioButton buttonWithType:UIButtonTypeSystem];
    NikiRadioButton * rb1 = [[NikiRadioButton alloc] init];
    rb1.frame = CGRectMake(50, 50, 200, 50);
    rb1.backgroundColor = [UIColor greenColor];
    [rb1 setTitle:@"男" forState:UIControlStateNormal];
    [rb1 setImage:[UIImage imageNamed:@"unchecked.png"] forState:UIControlStateNormal];
    [rb1 setImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateSelected];
    [rb1 addTarget:self action:@selector(onRadioButtonValueChanged:) forControlEvents:UIControlEventValueChanged];
    [rbg addObject:rb1];
    [self.view addSubview:rb1];
    
    NikiRadioButton * rb2 = [[NikiRadioButton alloc] init];
    rb2.frame = CGRectMake(50, 100, 200, 50);
    rb2.backgroundColor = [UIColor redColor];
    [rb2 setTitle:@"女" forState:UIControlStateNormal];
    [rb2 setImage:[UIImage imageNamed:@"unchecked.png"] forState:UIControlStateNormal];
    [rb2 setImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateSelected];
    [rb2 addTarget:self action:@selector(onRadioButtonValueChanged:) forControlEvents:UIControlEventValueChanged];
    [rbg addObject:rb2];
    [self.view addSubview:rb2];
    
    NikiRadioButton * rb3 = [[NikiRadioButton alloc] init];
    rb3.frame = CGRectMake(50, 150, 200, 50);
    rb3.backgroundColor = [UIColor lightGrayColor];
    [rb3 setTitle:@"不限" forState:UIControlStateNormal];
    [rb3 setImage:[UIImage imageNamed:@"unchecked.png"] forState:UIControlStateNormal];
    [rb3 setImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateSelected];
    [rb3 addTarget:self action:@selector(onRadioButtonValueChanged:) forControlEvents:UIControlEventValueChanged];
    [rbg addObject:rb3];
    [self.view addSubview:rb3];
    
    [rbg[0] setGroupButtons:rbg]; // Setting buttons into the group
    [rbg[0] setSelected:YES]; // Making the first button initially selected
    
    
    // 判断最终哪个按钮被点击了
    TSCMyClickBtn * btn = [TSCMyClickBtn buttonWithType:UIButtonTypeSystem];
    [btn setTitle:@"哪个RadioButton被选中了？" forState:UIControlStateNormal];
    btn.frame = CGRectMake(50, 250, 200, 50);
    [self.view addSubview:btn];
    btn.btnClickedListener = ^(TSCMyClickBtn * btn) {
        NikiRadioButton * rb = [TSCMyUIUtil getSelectedRadioButton:rbg];
        NSLog(@"被选中的的是：%@", rb.titleLabel.text);
    };
}
-(void) onRadioButtonValueChanged:(NikiRadioButton*)sender
{
    // Lets handle ValueChanged event only for selected button, and ignore for deselected
    if(sender.selected) {
        NSLog(@"Selected color: %@", sender.titleLabel.text);
    }
}

@end
